Force delete .php on request

I know with .htaccess, you can request a file without extension like (page.php) can be requested as (page).

Below is the code in the .htaccess file to enable this:

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

      

This code only works when requested (page). How to make it so that on request (page.php) only (page) is forcibly rewritten? Is there a way to do this?

+3


source to share


1 answer


You can put this code in your htaccess (which should be in the root folder)

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/(.+)\.php(?:\s|\?) [NC]
RewriteRule ^ /%1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.*)/?$ /$1.php [L,QSA]

      



Note: I wrote this code to make it work with /some_page.php

but also with/folder/subfolder/.../some_page.php

+1


source







All Articles