How to remove .php or .html extension using .htaccess file

how-to-remove-php-html-extension-using-htaccess

In this tutorial you will run “How to remove .php, .html extension using .htaccess file”. Many time we try to make our website more user friendly and search engine friendly. If you want to increase indexing of your website with google search engine then you need to make your website search engine friendly. In this tutorials, i will show you easy step by editing the .htaccess file.

What is an .htaccess file

First of all i want to tell you, what is an .htaccess file and why i will use?

.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories.

Please note that .htaccess is the file’s extension. It isn’t file.htaccess, it is simply .htaccess.

Feature of .htaccess

With an .htaccess file you can:

  • you can redirect user to current domain to another domain
  • you can redirect domain non-www to www or www to non-www
  • you can redirect domain http to https or https to http
  • Password protect a specific directory
  • Block users by IP
  • Preventing hot linking of your images
  • rewrite URIs

Removeing .php Extension

To remove .php file extension from a PHP file follow the below example:
Suppose your current website url is working as yoursite.com/user.php and you want to open as yoursite.com/user

you have to add the following code inside the .htaccess file

If you want to remove .html extension from a html file
Example:
yoursite.com/user.html to yoursite.com/user

you simply need to change .html instead of .php from above code.

Now you can link pages inside the HTML document without extension of the page. For example:

Adding a trailing slash at the end

Many users wantto add a trailing slash at the end of url. For this purpose you need to ignore the first (above) code and insert following code.

The first four lines deal with the removal of the extension and the following, with the addition of the trailing slash and redirecting.

Link to the HTML or PHP file as shown above. Don’t forget to change the code if you want it applied to an HTML file.

Note:- For GoDaddy users: To remove the .php or .html extensions you need to enable MultiViews before. The code should look like this:

Note: Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request

Related posts

Leave a Comment