How To Remove File Extensions Using .htaccess

Home » Server Software » Apache Tweaks » How To Remove File Extensions Using .htaccess
January 18, 2015 Apache Tweaks 2 Comments

In some occasions, you may want to remove the .php or .html extensions for instance from your URL’s in order to make your links look nice and improve your SEO.

If you are running your site on an Apache webserver and have mod_rewrite enabled you can certainly do so by following the instructions here.

To achieve this for dynamically generated PHP files you can add the following lines to your .htaccess file:

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

This will make the URL sample to convert to

The same can be done with HTML (.html or .htm) files by using the line below in your .htaccess file:

RewriteRule ^([^\.]+)$ $1.html [NC,L]

The sample above is for .html files. To do the same on .htm all you need to do is replace the “html” in the sample above (in red) for “htm”.

As in the previous example the URL sample will convert to

2 thoughts on : How To Remove File Extensions Using .htaccess

  • I am still having issue with my htaaccess. I put above code in htaccess file but it disable whole website. I am unable to open any link or page.

    I am using Apachee server

    My basic requirement is to change to

    waiting for solution.

    • The server you appear to use is running IIS which means that it’s a Windows server and Apache does not run the mod_rewrite module on Windows so the code in this recommendation does not apply as it’s only aimed for Apache with mod_rewrite. You will have to ask your host provider for the URL rewrite possibilities on the server you’re using and based upon what’s supported you can get more assistance.