.htaccess doesn't work on ubuntu droplet

May 5, 2015 10.4k views
Apache Configuration Management Ubuntu

I installed LAMP on my droplet and then I followed this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite and I used the contents for the file from my old web hosting, so I know it works:
RewriteEngine On
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUEST
RewriteRule ^(.*)$ $1.php [L,QSA]

However, if I enter for example http://cyan.red/index it comes up with:
Not Found

The requested URL /index was not found on this server.

3 Answers

By default the LAMP install will disable usage of the .htaccess file.

You need to edit the configuration file for your virtual host.

 $ nano /etc/apache2/sites-available/000-default.conf

Change the <VirtualHost> directive to look something like this. The important part is AllowOverride All, as this tells Apache that the directory can override default settings using a .htaccess file.

<VirtualHost *>
     ServerName cyan.red
     ServerAlias www.cyan.red
     DocumentRoot /var/www/html

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

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

Now make sure the website is enabled.

  $ a2ensite 000-default.conf

Also make sure that the rewrite mod is enabled.

  $ a2enmod rewrite

Now restart Apache

   $ service apache2 restart
  • Thanks, that worked! :D
    I had put the bit in the wrong place in the config file!

You know this command $ a2enmod rewrite is not mentioned in any DO tutorial, but without it I couldn't enable .htaccess, now can, thanks

Have another answer? Share your knowledge.