How to Remove File Extension .php, .html from URL using .htaccess

Here now we going to see how to remove the file extension .php, .html from the URL using .htaccess. The extension is a very important part for any files because extensions can only identify what kind of file you have. Every file format has it’s won extension example .html, .php, .css, etc., If you try to remove the file extension from the address bar and now you try to execute the URL it automatically redirect to .html or .php extension in the address bar. Using .htaccess you can remove this file extension from the address bar the rewrite method will help to solve this issue. The main purpose of removing the file extension is to secure your website from the hackers and for SEO (Search Engine Optimization). So here is the complete step by step tutorial for removing file extension.

First, create a .htaccess file in your root folder and add the following code in your .htaccess file to remove file extension. If you can’t see the .htaccess file here you here an article.

Removing .php Extension from URL

The following code will help to remove .php extension, for example from to Like this, the URL comes in the address bar.

In case of user try to access the contact.php this will not redirect. So in this now you need to write a few more rules in the .htaccess file. Below you have the code copy and past it in your .htaccess file.

Removing .html Extension from URL

As same like .php extension here you can remove the .html extension, for example, you need to remove the .html extension from to

By adding the above code the user can access the URL in the browser. Now you need to redirect complete URL. Now by adding the below code, you will redirect the users which typed complete URL from to

Was this article helpful?

Yes No

How can we improve it?


We appreciate your helpul feedback!

Your answer will be used to improve our content. The more feedback you give us, the better our pages can be.

Follow us on social media:

Facebook Pinterest


Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top