Popular Categories

How to remove .html extensions with .htaccess?

I was recently working over a project where i wanted to remove the .html extensions, in order to make the URLs more search engine friendly. To remove the .html extension from a HTML file for example yoursite.com/about.html to yoursite.com/about you have to add the following code inside the .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Place this snippet of code inside the file and place that file in root directory.

Note: A similar method can be used for removing other extensions, just replace html with your need. For example, to remove .php modify the code to following lines: 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Was this helpful? Did I missed something? Do you have a question? Get in touch.