January 28th, 2010

Rewrite Module in OS X 10.6

Setting up a development environment locally can save a lot of time, but the setup can be quite painful. I needed to modify a few things to getting my website running in OS X Snow Leopard. Setting up apache is wonderfully easy with OS X but further customization took more time. I wanted to get the .htaccess files and apache rewrite module functioning functioning locally.

This required me to change the directory settings in:
/private/etc/apache2/users/MYUSERNAME.conf

To (for example – depending on your target Directory):

<Directory "/Users/MYUSERNAME/Sites/">
	Options All
	AllowOverride All
	Order allow,deny
	Allow from all
</Directory>

This will allow/direct apache to search the folders for .htaccess files.

Because I was trying to use path based arguments I needed to use the rewrite module. It is already running by default in Snow Leopard – if it isn’t you will need to edit your /etc/apache2/httpd.conf file. I put the following in my /Users/MYUSERNAME/Sites/.htaccess file to get path arguments working:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I copied it from the WordPress .htaccess files. This still didn’t quite work though. For some reason this was redirecting the request to the main DocumentRoot variable set in /etc/apache2/httpd.conf so I changed that variable to the following:

#Commented out old path
#DocumentRoot "/Library/WebServer/Documents"
#Added new path pointing to my directory
DocumentRoot "/Users/MYUSERNAME/Sites/"

I restarted apache and it works. While I’m fairly sure this is the correct way to get .htaccess files working, there must be a better way of getting the rewrite module to work for each user – rather than cannibalizing the DocumentRoot.

Tags: , , , , ,

Leave a Reply