How to Remove file extension from URL using htaccess

how to Remove file extension from URL using htaccess file

Many times you want to remove the URL extension (. php, . html, .jsp, etc.) from your website. Example

https://www.yourdomain.com/index.php  https://www.yourdomain.com/index

In this tutorial, I will show how to Remove file extension from URL using htaccess file.

.htaccess file is a server configuration file.  the file contains below server configurations

1. Project directory
2. Page redirection from one to another configuration
3. Block Suspicious IP traffic
4. Rewrite URLs
5. Remove URLs extension like (.php, .html etc)
6. password protect your website directory

Following the steps to Remove file extension from URL using htaccess

1. Login to your server via FileZilla FTP
2. Go to the project directory
3. Create .htaccess file on your project directory and add the below following code inside the .htaccess file. This file can be easily edited in any text editor.

This code is remove the .php extension from your website

If you want to remove the .html extension from html file from https://www.yourdomain.com/index.html to https://www.yourdomain.com/index. you need to add the below code inside your .htaccess file.

If you are using the Godaddy server then you need to add the MultiViews tag before starting. Example.

After configuration, If the user enters the URL as https://www.yourdomain.com/index.html it will automatically redirect to https://www.yourdomain.com/index

Download the sample .htaccess file and you can also visit stackoverflow.com