I'd plastered all over the Internet that this code in your .htaccess file will remove the file ending:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

However, although enables the URL without file ending, it does not disable the URL with file ending.

Essentially, what I'd like to force any attempt for an request with file ending (domain.com/sample.php) to end up without file ending (domain.com/sample)

I'm sure someone will have covered this somewhere, but I cannot find anything.

Many thanks.

有帮助吗?

解决方案

Add this extra rule before your existing rule:

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top