(+91) 90339 45303 info.hitinfotech@gmail.com kaushik.savani.1990
How to remove .php, .htm and .html extension using .htaccess

How to remove .php, .htm and .html extension using .htaccess

 

If you want to remove .php, .htm and .html extension from website URL’s Link, then here’s the code you have to write in your .htaccess file. .php extension is removed to make url user and seo friendly. It is recommended to don’t disclose technology name in the url (uniform resource locator).

 

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#for remove html extension
RewriteRule ^([^\.]+)$ $1.html [NC,L]

 

When you will use this code you should remove .php from all pages which are used to link the PHP files, otherwise it will show the error.


What is an .htaccess file

An .htaccess file is a simple ASCII file that you create with a text editor like Notepad or TextEdit. The file lets the server know what configuration changes to make on a per-directory basis.

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

.htaccess files affect the directory in which they are placed in and all children (sub-directories). For example if there is one .htaccess file located in your root directory of yoursite.com, it would affect yoursite.com/content/yoursite.com/content/images/, and so on…

It is important to remember that this can be bypassed. If you don’t want certain .htaccess commands to affect a specific directory, place a new .htaccess file within the directory you don’t want to be affected with the changes, and remove the specific command(s) from the new file.