Hiding HTML File Extension in URL with Apache mod_rewrite on Ubuntu 14.04

Enable the mod_rewrite module using the a2enmod command. If you can't remember the specific name of the module you are trying to enable, you can ls /etc/apache2/mods-available/ or if you'd like to see if the module is already active you can take a look at /etc/apache2/mods-enabled/.

a2enmod rewrite.load

In /etc/apache2/sites-enabled/000-default.conf you'll need to add the following directives inside of the proper VirtualHost. If you're using PHP, you can substitute $1.html for $1.php.

  • <Directory /var/www/html>
    • RewriteEngine On
    • RewriteRule ^([^\.]+)$ $1.html [L]
  • <Directory>

After you restart Apache you'll be able to omit html file extensions from your URLs.


Was this article helpful?

mood_bad Dislike 2
mood Like 0
visibility Views: 5473