Enable Apache mod_rewrite on OS X 10.5 Leopard

Leopard has introduced a few changes in the default paths for Apache configuration. As a reference for setting up Apache, I have decided to post a simple tutorial on modifying the config, which details the new locations. For this tutorial I will demonstrate how to enable mod_rewrite, the Apache URL rewriting engine.

NOTE: This post assumes the stock install of Apache that ships with OS X Leopard. The version I am using is Apache 2.2.8.

To enable mod_rewrite for the parent Apache config, open Terminal. Using sudo, open httpd.conf with vi or your favorite text editor:

$ sudo vi /private/etc/apache2/httpd.conf

Uncomment the following line:

LoadModule rewrite_module libexec/httpd/mod_rewrite.so

In addition to the above httpd.conf config in /private/etc/apache2/, there is a separate users directory which contains unique config files for each user on the machine. Therefore, we must enable mod_rewrite in both /private/etc/apache2/httpd.conf and /private/etc/apache2/users/[user].conf.bak for any sites under Sites/. This process is detailed for my user ‘markb’ below.

Create a backup of the user config:

$ sudo cp /private/etc/apache2/users/markb.conf /private/etc/apache2/users/markb.conf.bak

Next, open markb.conf in vi or any text editor:

$ sudo vi /private/etc/apache2/users/markb.conf

Change the first to lines to the following:

Options All
AllowOverride All

Restart Apache:

$ sudo apachectl restart

Now, you can test the rewrite engine and exploit friendly URLs by creating an .htaccess file in any directory under Sites/.

Share your thoughts