.htaccess not removing file extensions

February 5, 2018 1.7k views
Ubuntu Apache

So here is the link in question:

The setup of my .htaccess file is as follows:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
ErrorDocument 404 /404.html

So it should be removing the .html part, but when you navigate to the link, it errors:

Any thoughts or suggestions?

edited by kamaln7
1 Answer

The rules look fine to me, so I’m suspecting that Apache isn’t reading the .htaccess file in the first place. That could happen if it is not configured to do so. Open your VirtualHost config (usually /etc/apache2/sites-enabled/file) and make sure AllowOverride is set to All like so:

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

Restart Apache so that the changes take effect.

  • I’ve edited that conf file to read:

    <VirtualHost *:80>
    ServerAdmin jonathandelcontedesigns@gmail.com
    ServerName cybergamegear.com
    ServerAlias www.cybergamegear.com
    DocumentRoot /var/www/cybergamegear.com/publichtml
    ErrorLog ${APACHE
    CustomLog ${APACHE
    LOG_DIR}/access.log combined
    <Directory /var/www/html>
    Options FollowSymLinks
    AllowOverride all
    Require all granted

    and restarted apache2, but still nothing. :c

    • Almost there! You just need to update the Directory block to match your DocumentRoot:

       <Directory /var/www/cybergamegear.com/public_html>

      That should hopefully get the .htaccess file to work

Have another answer? Share your knowledge.

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