Getting mod_rewrite to work on Mac OS X

11 Feb 2005 9:44 - (0) comments

First you'll need to uncomment the lines for mod_rewrite in the Apache config file /etc/httpd/httpd.conf. Remove the # from the following lines:

#LoadModule rewrite_module libexec/httpd/mod_rewrite.so
#AddModule mod_rewrite.c

You don't want to lose your configurations in case Apple decides to update the Apache config file with a system update. Luckily, the httpd.conf file also includes all *.conf files in the /etc/httpd/users directory.

I'm using .htaccess for mod_rewrite. To allow .htaccess files to override settings change AllowOverride None to AllowOverride All for the Apache directory (there is already one for your personal websharing directory). Open /etc/httpd/users/YOURUSERNAME.conf and add the following to your existing configuration:

<Directory "/Library/WebServer/Documents/">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>

If you run Apache in a different directory change /Library/WebServer/Documents/ to the path of your directory.

To see if everything works restart Apache from the terminal with sudo /usr/sbin/apachectl restart. If it's not working correctly check the Apache error log with tail -f /var/log/httpd/error_log. Be sure to check if the .htaccess files are included by adding some random characters to the .htaccess file. If .htaccess is included Apache should produce a server error.

If you have trouble with mod_rewrite you can add the following to the .conf file and view all debugging info:

RewriteLog "/private/var/log/httpd/rewrite_log"
RewriteLogLevel 9

Remember to remove it again after the debugging.

Comments

No comments allowed.

Admin