Search code examples
apachemod-rewritetrac

apache mod_rewrite <directory> precedence over <location> with svn and trac


I have an apache config file,

<VirtualHost *:443 >

    SSLEngine on
    SSLCertificateFile ...
    SSLCertificateKeyFile ...
    SSLCertificateChainFile ...
    SSLCACertificateFile ...


    ServerName www.etebaran.com
    ServerAlias www.etebaran.com etebaran.com 
    ServerAdmin webmaster@etebaran.com
    DocumentRoot /home/etebaran/domains/etebaran.com/private_html
    ScriptAlias /cgi-bin/ /home/etebaran/domains/etebaran.com/public_html/cgi-bin/

    UseCanonicalName OFF

    SuexecUserGroup etebaran etebaran
    CustomLog /var/log/httpd/domains/etebaran.com.bytes bytes
    CustomLog /var/log/httpd/domains/etebaran.com.log combined
    ErrorLog /var/log/httpd/domains/etebaran.com.error.log
    ErrorDocument 400 default
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 405 default
    ErrorDocument 408 default
    ErrorDocument 410 default
    ErrorDocument 411 default
    ErrorDocument 412 default
    ErrorDocument 413 default
    ErrorDocument 414 default
    ErrorDocument 415 default
    ErrorDocument 500 default
    ErrorDocument 501 default
    ErrorDocument 502 default
    ErrorDocument 503 default

<Location /svn>
    #Options -All
    DAV svn
    SVNPath /home/etebaran/svn/

    AuthzSVNAccessFile /home/etebaran/svn/conf/authz
    Satisfy Any
    Require valid-user
    AuthType Basic
    AuthName "Etebaran Repository"
    AuthUserFile /home/etebaran/svn/conf/.htpasswd
    SVNAutoversioning on 
</Location>
<Location /trac>
    SetHandler mod_python
    PythonHandler trac.web.modpython_frontend
    PythonOption TracEnv /home/etebaran/trac
    PythonOption TracUriRoot /trac
    Satisfy Any
</Location>
<LocationMatch "/trac/login">
    AuthType Basic
    AuthName "Etebaran Trac"
    AuthUserFile /home/etebaran/svn/conf/.htpasswd
    Require valid-user
</LocationMatch>
    <Directory /home/etebaran/domains/etebaran.com/private_html>
        Options +Includes -Indexes
        RewriteEngine On
        RewriteCond %{query_string} ^(.*)
        RewriteRule (.*) etebaran/_japp/controller.php?__r=$1&%1 [L]
        suPHP_Engine ON
        suPHP_UserGroup etebaran etebaran
    </Directory>
</VirtualHost>

The problem is, <Directory> has precedences over <Location>, so the rewrite rule on directory overrides locations.

Oddly, etebaran.com/svn still works, but etebaran.com/trac is handled by the directory directive and the PHP framework lying there.

I know there are nasty workaround, but what's the neatest one?


Solution

  • The issue seems to be your RewriteCond line. Your match pattern is ^(.*), which will match essentially anything. Use a more detailed match pattern to ensure that it won't match the URLs of your other tools. For example, a pattern of !^/svn/.* should match any URL that doesn't start with "/svn/".

    Your Subversion and Trac installations seem to use URLs that start with "/svn/" and "/trac/", respectively. What do the URLs for your PHP framework look like? Do they start with a prefix as well, or are they served from the root of the site?