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

I reinstalled my Ubuntu server and had to enable the use of .htaccess files again so I am making this short tutorial for those of you who may have to do the same.

Edit your apache2.conf:

  • sudo nano /etc/apache2/apache2.conf

Uncomment AccessFileName .htaccess:

  • press CTRL + W to search for the line with ‘AccessFileName .htaccess’
  • type ‘AccessFileName .htaccess’ then press ENTER
  • uncomment the line (remove the # sign) if it is commented out

Scroll up to change ‘AllowOverride’ in the document root:

  • find
  • change AllowOverride None to AllowOverride All

Save the file:

  • press CRTL + O to save
  • press CRTL + X to exit nano

Restart apache:

  • type sudo systemctl restart apache2 to restart apache if running Ubuntu 16.04
  • type sudo service apache2 restart to restart apache if running Ubuntu 15.10 or lower

And now your .htaccess file should be working.

Tags: ,