How to remove .php or .html or any other extension from your URL using .htaccess

Tutorial to remove .html or.php extension from URL using .htaccess file 

Recently I was wondering if I create an HTML website and make it look like a dynamic website and make them more search engine friendly.

I wanted to remove both .php and .html extensions from the end of my URLs. If you are also looking to do the same, you can do this simply by editing your.htaccess file.

Let me make it a bit easier for you.

First understand, what is a .htaccess file!

It is a simple ASCII file you can create in a notepad editor and name it “.htaccess” . Please note that your file may not work if it is .htaccess.txt instead of .htaccess.

An .htaccess file affects the directory location and also the subfolders of the directory.

What all you can do with .htaccess file ?

  1. You can redirect the user to a different page
  2. Block IP address
  3. Prevent image hotlinking
  4. password protect your directories
  5. Mention your own error documents

We will stick to rewriting urls like .php or .html in this tutorial

Removing Extensions

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

The above example is to remove .php extension from a file name in your URL.

Let us say for an example, if your URL is , it will hide .php from this URL and make it .


If you want to rewrite .html extension, you can replace the last line of above code to this single line code.
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This is all you have to do. Now you can link your page URL like this to an image

<a href=”” target=”_blank”><image src=”/images/sampleimage.jpg” /></a>

Was this post helpful?

1 thought on “How to remove .php or .html or any other extension from your URL using .htaccess”

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.