How to enable use of .htaccess in Apache on Ubuntu?

First Step

Open file as

sudo vim /etc/apache2/apache2.conf

Second Step

remove comment sign (#) if you find it before this line ( line number 187 approx.)

AccessFileName .htaccess

Third Step

Then find the line where there is

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

replace "None" with "All"

AllowOverride All

And voila... .htaccess works!!


Activate ModRewrite:

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart