rewrite
Configuring Leopard’s Apache to work with all Rewrite Rules
Although there are a few blog posts out there detailing how to enable .htaccess on Mac OSX 10.5. I didn’t find anything that could help me with a problem I had with a specific RewriteRule.
This post isn’t specific to Leopard but maybe useful to users of this OS due to the default values that it’s pre-installed Apache’s httpd.conf comes set with.
Say for SEO reasons you wanted to rewrite
product.php?id=17
as
product/toaster/17.html
You could use the following rewrite rule:
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
In other blogs it will tell you that you will need to change AllowOverride None to AllowOverride All in the <Directory “/Library/Webserver/Documents”> of /private/etc/apache2/httpd.conf and perhaps also in any conf files found in /private/etc/apache2/users. (This is not enabled by default on Leopard).
What they won’t neccesarily tell you is that to get rewrite rules like the above working you need to remove MultiViews from your Options list, leaving you with something like this :
<Directory "/Library/Webserver/Documents"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>
I hope this saves someone the trouble I went through this morning trying to figure it out.
For a quick explanation see the short but sweet Apache Multiviews are evil
MarkB
Categories
Archives
- August 2010 (2)
- June 2010 (1)
- March 2010 (1)
- January 2010 (1)
- August 2009 (1)
- July 2009 (1)
- May 2009 (1)
- April 2009 (2)
- March 2009 (1)
- February 2009 (2)
- October 2007 (1)
- May 2006 (1)