.htacess not working on localhost

For the benefit of someone else with the same problem, in addition to enabling mod_rewrite (the command sudo a2enmod rewrite should work, on Linux), you also have to open up the file where you’ve defined your VirtualHost (by default, it’s /etc/apache2/sites-available/default) and then make sure your value for ‘AllowOverride’ is ‘All’.

Basically, you should have a line that reads:
AllowOverride All

Once you make the edit, make sure you reload/restart Apache.

What this does is, it tells Apache that it’s ok to allow users to use any directive in their .htaccess file to override the default Apache settings.

If the ‘AllowOverride’ is set to ‘None’, then your rules in .htaccess won’t work.