1&1 .htaccess / RewriteRule woes
April 2nd, 2008Afternoon all,
I’m posting this in the hope that it gets picked up by search engines on how to solve this painful problem!
Let me set the scene: We designed a website for a client, who rather than use our wonderful dedicated hosting plan, decided they wanted to remain with their current host, 1&1. Fair enough, we don’t dictate where clients have to have their sites hosted, so long as they support PHP and .htaccess URL Rewriting, which 1&1 claim to do.
The first warning sign was when I realised an AddType wasn’t working. Apparantly, 1&1 don’t use the pretty much de-facto MIME type of application/x-httpd-php, instead preferring x-mapp-php4 and x-mapp-php5 for PHP 4 and 5 respectively.
However, the real headache came with actual URL Rewriting, for example redirecting /aboutus/ to /index.php?page=aboutus, it just WAS NOT working.
Lots of reports about it online, and many solutions that worked for others, but not for this. In the end, I ended up calling 1&1, who after 25 minutes, most of it being put back on hold to “check the information”, couldn’t grasp that the /aboutus/ directory was the problem as it didn’t exist. 3 times I told them “it doesn’t have to exist, the .htaccess file is supposed to catch that and send it to the right page. I’ve tested it on my dev box and it works fine!”
In the end I had to hang up before I lost my temper with her down the phone. Eventually, I finally stumbled across the solution! I stumbled across a blog by Elliott Back complaining of a very similar problem, albeit with WordPress permalinks. So I thought I’d give it a go, and it only bloody worked!
So here’s the solution:
In your .htaccess, add this to the top (or add it to your existing Options declaration):
Options -MultiViews
And here’s the reasoning, thanks to Elliott:
It turns out that 1and1 (without telling me) enabled the apache Multiviews setting, which plays havoc with the rewrite rules…
…Since I also had a file called archives.php, Apache couldn’t decide whether to apply the rewrite rules in .htaccess or the multiviews logic that said all /archives/ were really archives.php.
So a big thank you to Elliott for saving me from another life-shortening call to 1&1!
James.