问题
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.
回答1:
Add this extra rule before your existing rule:
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
来源:https://stackoverflow.com/questions/21601051/htaccess-remove-and-disable-file-ending