How to remove .php extension with .htaccess

How to remove .php extension with .htaccess


If you want to remove .php extension from the 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 the 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 a .htaccess file?

A .htaccess file is a simple ASCII file that's created with a text editor like Notepad.

It changes configuration according to pre-directory basis.

.htaccess topics:

Best WordPress Hosting


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price

Leave a Reply

    Waiting for your comments