Reputation: 51
So recently, I have been trying to remove URL extensions from my website URL's, it has been successful and is working. However, when a URL extension has been removed from a page and ends in: "/Contact". A user can change the URL to "/Contact.php" and the URL will stay like it. I do not want that, regardless of them typing in "/Contact.php" I want it to revert to "/Contact".
Htaccess code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Upvotes: 0
Views: 60
Reputation: 18671
You can use:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Upvotes: 1