Search code examples
phpapache.htaccessmod-rewritelamp

.htaccess RewriteRule conflict across different directories


On my Ubuntu development machine(s) I run a LAMP stack. For each website I work on, I create a new directory off root:

/var/www/somesite.com

/var/www/anothersite.com

The problem I have is that apache wont allow duplicate rewrite rules across these folders. For instance, If I set up this:

RewriteRule ^track/(.*)$ /somesite.com/order_track.php [nc,L]

http://localhost/somesite.com/track/abc123 - works as intented

This same declaration wont work on anothersite.com

RewriteRule ^track/(.*)$ /anothersite.com/order_track.php [nc,L]

http://localhost/anothersite.com/track/abc123 - Apache returns a 404.

Clearing browser cache and restarting Apache have no effect. Apache seems to "remember" the first like rewriterule used. This happens on all of my computers(Home, work, laptop)

Edit: I should have mentioned that I have an htaccess file in each directory. The root /var/www does not contain an htaccess file. Each directory's htaccess should operate independently. But they do not.


Solution

  • You can have this in /somesite.com/.htaccess:

    RewriteEngine On
    RewriteBase /somesite.com/
    
    RewriteRule ^track/(.*)$ order_track.php [NC,L]
    

    Then this in /anothersite.com/.htaccess:

    RewriteEngine On
    RewriteBase /anothersite.com/
    
    RewriteRule ^track/(.*)$ order_track.php [NC,L]