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 opens purchase.php
  • https://example.com/foo opens foo.php
  • https://example.com/bar gives a 404 as bar 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?

  • 1
    Apache 2.2 and 2.4 are very different servers. Can you upgrade your test server to 2.4? I don't know of any big differences specifically with mod_rewrite, but I had to make many configuration changes when I upgraded a few years ago: httpd.apache.org/docs/2.4/upgrading.html In general this is why you want to do your testing on a machine that is as close to possible as your production server. Using a different OS and version of Apache is just a disaster waiting to happen. Sep 18, 2018 at 13:16
  • Yep, pointless testing locally if they are not identical setups. Sep 18, 2018 at 14:15
  • @StephenOstermiller Yeah, it's rather caught me out that a new install of MAMP isn't up to date with Apache versions - I'll move to a virtual machine running the same system in future. I will also look through the change log and see if I can find anything breaking
    – Rory
    Sep 18, 2018 at 14:35
  • 1
    The URLs working without the extension is caused by the Multiviews option, which is compiled into Apache by default and can be enabled and disabled per directory with Options Multiviews or Options -Multiviews Sep 18, 2018 at 16:44
  • Whether or not .htaccess takes effect is controlled by AllowOverride Sep 18, 2018 at 16:46

1 Answer 1


So I eventually worked this out by going line to line changing redirects to https://google.com to see which worked and which didn't. Any patterns in the .htaccess that had a matching php file wouldn't load.

I think it's a configuration difference between the two rather than a version difference and was fixed immediately in my case by adding Options -MultiViews to the top of my .htaccess file. They then all worked as expected - perhaps multiviews was disabled on my test server.

  • Yes, this is simply a config difference, not a difference in the Apache version. MultiViews is not enabled by default on any version of Apache. So, for some reason, it has been explicitly enabled on your "production server".
    – MrWhite
    Sep 18, 2018 at 20:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.