How to enable apache2 mod_rewrite on Mac?

When we use web server as apache2 very often we need mod_rewrite rules to be enabled. In case of linux kernel based OS enabling the mod_rewrite is easy. A single command can enable it. For Mac OS it is bit different.

To enable mod_rewrite on Mac we need to the followings:

Step #1: Open the httpd.conf file

 $ sudo vi /etc/apache2/httpd.conf

Step #2: Uncomment the following line

#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
to 
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Step #3: Restart the apache

$ sudo apachectl restart

This should enable the mod_rewrite for apache2

If you try using a2enmod to enable the mod_rewrite rules in Mac will not work as a2enmod was written for the Debian distribution, as it is a Debian-specific.

Share