1

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.

2 Answers 2

0

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]
Sign up to request clarification or add additional context in comments.

4 Comments

While it does work, this feels like a work-around. I'd rather know why Apache behaves like this. Thanks for the input!
I say it is a work around because, from what I've read, Apache should not be behaving in this manner. Each htaccess file in the sub-folders should operate independently. I've found no other way to correct the problem, therefore I'm using the solution you provided.
There's are many cases when sub folder's htaccess inherits parent htaccess. What you have here is a standard htaccess rewrite behavior.
There is no htaccess in the parent folder. These are two htaccess file independent of each other. In separate directories off root, with no htaccess files above them. There should be no conflict, yet there is.
0
RewriteCond %{HTTP_HOST} ^(?:www\.)?(somesite\.com|anothersite\.com)$
RewriteRule ^track/ /%1/order_track.php [NC,L]

you don't need (.*) if not needed to catch this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.