I've run into an issue when moving from a test server to a production server. I have a set of .htaccess
rules in a file in the public_html
site root:
#Root directory htaccess
RewriteEngine On # Turn on the rewriting engine
#Rewrite rules for purchase areas
RewriteRule ^purchase\/(\S+) purchase.php?product=$1 [NC,L] #Purchase a named product
RewriteRule ^purchase purchase.php [NC,L] #Purchase page
On my test server, these work perfectly loading the correct page each time.
On the production server, everything after the first slash seems to be ignored and a 404 is given. The other .htaccess
rules work fine, it just seems to be ones with two levels that don't work as expected.
What have I done wrong, and what can I do to make this consistent?
- Test Server document root
http://localhost:8888/
Apache/2.2.34 (MAMP) - Live Server document root
https://example.com/
Apache/2.4.6 (CentOS)
First update
I have spent a good few hours on this now and in a bout of frustration deleted my .htaccess
. I was very surprised to see that some redirects were still working - and it turns out my .htaccess
file was doing absolutely nothing aside from custom errors.
Currently, wherever a PHP file exists with a matching name to the URL are opened directly - without any .htaccess
in the directory - eg:
With no .htaccess
in the directory:
https://example.com/purchase
openspurchase.php
https://example.com/foo
opensfoo.php
https://example.com/bar
gives a 404 asbar
isn't a file in this directory.
Is this typical Apache behaviour or is there a rule in a different config I need to track down and override?
Options Multiviews
orOptions -Multiviews