Enable mod_rewrite on OS X 10.4 (Tiger)
Tiger has introduced a new super-confusion level to the stock configuration of Apache. In addition to the httpd.conf file in the /etc/httpd directory, there’s now a new users directory as well. That directory holds unique config files for each user of the machine. So, if you were to enable mod_rewrite or AllowOverrides in httpd.conf, you may find that it doesn’t quite cut the mustard in your personal Sites directory. Let’s take a look:
To enable mod_rewrite:
- Open
/etc/httpd/httpd.conf
(I highly recommend TextMate – from the command line you can simply type this:
$ mate /etc/httpd/httpd.conf
or use the old standards: vi, vim, whathaveyou) - Go to line 223 (if your config file just so happens to jive with mine) and uncomment the following line:
LoadModule rewrite_module libexec/httpd/mod_rewrite.so
(mind the wrap) - Go to line 267 and uncomment the following line:
AddModule mod_rewrite.c - Scroll down to line 408 and change the line to read:
AllowOverride All
(Some server admins will tell you this may not be the best idea for hosting a live site, but I’m assuming you’re using this for local development only, right?) - Uncomment line 454:
AccessFileName .htaccess - Restart Apache:
$ sudo apachectl restart
At this point you should have mod_rewrite happily fixing your ugly URL’s in the /Library/WebServer/Documents directory, but it’s not working in your /Users/you/Sites directory. What gives? Here’s the trick:
- Open the
yourname.conffile in the/etc/httpd/usersfolder. - Change the first two lines to this:
Options All
AllowOverride All - Give Apache another bounce:
$ sudo apachectl restart
You should now be seeing friendly url’s in your very own Sites directory.
