Enable mod_rewrite in LAMP

mod_rewrite is an Apache module that allows to rewrite requested urls on the fly using rule based rewrite engine. In simple language it is the module that empowers your .htaccess file. It is not activated by default. So you’ll notice your htaccess rules won’t work on fresh install of Apache. In this tutorial we’ll see how to activate this module.

This tutorials is for the LAMP (Linux) stack. In case you are using WAMP (Windows) then instead please follow this link.

Step I: Activate mod_rewrite

Run below command to enable this module.

Step II: Set AllowOverride directive to all in your vhost file

In case you are not using any virtual hosts then open /etc/apache2/apache2.conf in vim (or any of your favourite file editor).

Search for below block of lines.

We need to change AllowOverride None in above code to AllowOverride all. So after this modification above block of code looks as below

Just in case you are using virtual hosts then you’ll need to search for above code in /etc/apache2/sites-available/{somename}.conf

Step III: Restart apache

Restart apache server for the changes to take effect.

That’s it. Your .htaccess file rules should now work.

Leave a Reply

Your email address will not be published. Required fields are marked *