问题
I use htaccess to remove .php extension from URL. The problem comes up when there's a file and a directory with the same name. By removing .php extension the server thinks I'm trying to access a directory a denies the access.
EXAMPLE www.europe.com/italy.php turns into www.europe.com/italy but as I have a folder named italy, the servers denies the access saying "Forbidden, You don't have permission to access /italy/ on this server"
Here's my HTACCESS
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
UPDATE: Final code working like a charm!
DirectorySlash Off
IndexOptions FancyIndexing
Options All
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*[^.]+\.php
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(([^/]+/)*[^/.]+)$ /$1.php [L]
来源:https://stackoverflow.com/questions/14908303/htaccess-issue-with-directory-when-removing-extension