Apache htaccess and directive multiviews

Nowadays it is common to use a .htaccess file to configure access to directories and also mask URL’s that point to internal URL’s. Well today, we had to point a URL of http://www.mydomain.com/solution to an internal URL like http://www.mydomain.com/solution.cfm.

Actually no big deal, since the .htaccess comes to the rescue. We quickly put a .htaccess together with the simple lines of:

RewriteEngine On
RewriteRule ^([a-z]+)$ /$1.cfm

But alas, it did not work. We always got an error message saying that the URLĀ  http://www.mydomain.com/solution could not be found. We thought that the .htaccess file was not working or we had a typo. We even restarted the whole server to see if that had any effect. But still we could not get the rewrite rule to work. Strangely the rule *did* work when we used something like:

RewriteRule ^([a-z]+)$ /test.cfm

Apparenlty, Apache was looking for the same directory and was not matching our rule, but only if the URL and the filename had the same name! So, after a long time looking for a solution we figured out that we had “Multiviews” enabled for all of our hosts. Multiviews is part of the “Content Negotiation package” of Apache. In its own words “Content Negotiation” is about;

“It can choose the best representation of a resource based on the browser-supplied preferences for media type, languages, character set and encoding. It also implements a couple of features to give more intelligent handling of requests from browsers that send incomplete negotiation information.”.

Point is that the Multiviews directive interefered with our rewrite rule. Thus the solution to get our rewrite rule to work properly was to add a custom directive to the host in question without the Mutliviews option.

A comprehensive documentation on Multiviews can be found over at the Apache docs.

If you enjoyed this post, make sure you subscribe to my RSS feed!

About this entry