user2656114
user2656114

Reputation: 980

Strip PHP extension using .htaccess

I am using

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

in .htaccess file.

It works ok in that www.site.com/about shows the about.php page, but it still allows users to strictly specify .php, for e.g. www.site.com/about.php does not strip the .php.

Is it possible to do this, so even when they type the .php extension it strips it but still shows that page?

Thanks

Upvotes: 1

Views: 111

Answers (1)

anubhava
anubhava

Reputation: 786091

You can add this rule before your current rule:

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

Upvotes: 1

Related Questions