PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] .htaccess RewriteRule conflict across different directories

 March 15, 2022     .htaccess, apache, lamp, mod-rewrite, php     No comments   

Issue

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]


Answered By - anubhava
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing