mod_rewrite is an Apache module that used for url manipulation mechanism. Enable mod_rewrite module on Apache to provide rule based rewriting engine that can rewrite requested url on the fly. This is a simple and LATEST GUIDE to enable mod_rewrite module. Works with LAMP on Ubuntu 12.14, 14.04, 14.10, and all latest releases. And other linux distributions like CentOS, Redhat, etc.
How to Enable mod_rewrite on Apache
Step 1. First activate/enable mod_rewrite module by running the command below.
sudo a2enmod rewrite
Step 2. Then enable the .htaccess file and allow .htaccess file to override the standard apache configurations. To do this, edit your default website’s or default virtual host’s configuration file and add the following configuration lines (3 lines) and save the configuration file.
sudo vim /etc/apache2/sites-available/000-default.conf
You should add the below 3 lines to anywhere between the <VirtualHost *:80> and </VirtualHost>
<Directory "/var/www/html"> AllowOverride All </Directory>
Step 3. After all, restart apache2 service to take effect all the changes made in previous steps.
sudo apache2 restart
Tip: In case you need to disable mod_rewrite module , run the command below.
sudo a2dismod rewrite