Remove the .html or .php from the URL or link of the Website

What is the best way to remove ".html" or ".php" from a website URL or link.

Remove the .html or .php from the URL or link of the Website

Use the following .htaccess code to quickly remove the URL (www.url.com/contact.html) or the php URL (www.url.com/contact.php) from your website or URL

Here's an example of what your website might look like when it opens:

"www.url.com/contact.html"  or  "www.url.com/contact.php

Please add the following code to the root .htaccess file of your site if you wish to remove the .html & .php extensions from the URLs and websites:

"For HTML Websites

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L,NE]

"For PHP Websites

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L,NE]

The result of adding your website will be as follows: (example)

"www.url.com/contact

It will also help with redirects if someone opens ("(www.url.com/contact.html" ) by force, it will reroute to ( "(www.url.com/contact" his will prevent duplicate website content issues.

NOTE : It is recommended that you back up your existing .htaccess file before adding these rules.