How to Remove php Extension from URL

The extension does not matter for SEO ranking, but for better experiences, we can remove the .php or .html extension from a static website.

To remove the extension we have to create a .htaccess file and put it under the website document root folder.

And then add the following code into the .htaccess file.

//put this code in the root file .htaccess

RewriteEngine on

#remove extension html

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.html -f

RewriteRule ^(.*)$ $1.html [NC,L]


#remove extension php

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^(.*)$ $1.php

And then remove the .php extension from your header file (if your site is still showing the .php extension).

Suppose your site is then remove the ‘.php’ from href section.