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

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 www.example.com/filename.php , it will hide .php from this URL and make it www.example.com/filename .

Similarly,

If you want to rewrite .html extension, you can replace the last line of above code to this single line code.

 

This is all you have to do. Now you can link your page URL www.example.com/filename.html like this to an image

<a href=”https://www.example.com/filename” target=”_blank”><image src=”/images/sampleimage.jpg” /></a>

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave A Comment?

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