How to enable mod_rewrite for virtual host

If you are using latest apache version 2.4+ then here is the process how to enable mod_rewrite.

Go to etc/apache2/
Open apache2.conf using your favorite text editor.
Change

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

to

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Then save it. Remember you should have root permission to edit and save this file.
Now restart apache.

service apache2 reload

This process will enable mod_rewrite for apache server including virtual host.

You can also check if it's enabled or not. Create a php script

<?php    
phpinfo();    
?>

Load it from server. Under Loaded Modules section check if mod_rewrite is there or not. If it's there then it is enabled.


Enable Rewrite using

# sudo a2enmod rewrite

Then restart the apcahe2 using

# service apache2 restart

Enable in Virtualhost by adding

AllowOverride FileInfo

Then restart the apcahe2 using

# service apache2 restart

example:

<Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            # I Have below line from none to FileInfo
            AllowOverride FileInfo
            Order allow,deny
            allow from all
    </Directory>