How to enable apache2 mod_rewrite on Mac?

When we use apache2 as the webserver, very often we need mod_rewrite rules to be enabled. In the case of Linux kernel-based OS, enabling the mod_rewrite is easy. A single command can enable it. For Mac OS it is a 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/
LoadModule rewrite_module libexec/apache2/

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, it will not work as a2enmod was written for the Debian distribution, as it is Debian-specific.