.htaccess doesn't work on ubuntu droplet

I installed LAMP on my droplet and then I followed this tutorial: and I used the contents for the file from my old web hosting, so I know it works: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [L,QSA]

However, if I enter for example it comes up with: Not Found

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

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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 *>
     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

In my case, I was still hitting my head against the wall even after adding AllowOverride all to <VirtualHost *:443>conf.

I discovered you’ll need to remove AllowOverride all from your <VirtualHost *:80> conf if it’s been specified there.

None of this worked for me. What did work was to enable “AllowOverride all” in the apache2.conf file in /etc/apache2. For me it was on line 172 of that file. I tried everything else to eliminate my pages from giving a 404 when visiting pages but the homepage.