问题
How can I set up an htaccess that can distinguish a file from a folder with the same name?
I have under my website
index.php
team.php
team/Justin.php
team/martin.php...
and a htaccess with a URL Rewrite to make nice url and remove the .php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Unfortunately when I go to the url mywebsite.com/team it goes straight to the team folder... I would like
mywebsite.com/team goes to --> team.php page
mywebsite.com/team/xxx goes to --> any pages in the folder team.
Thanks,
回答1:
This is because /team maps to an existent directory. When you request /team server changes the uri to /team/ adding a directory slash thus it goes to the dir.
You have to turn off the DirectorySlash.
Add the following line to your .htaccess
DirectorySlash off
This will allow you to access /team.php as /team without trailing slash.
You can use this htaccess :
DirectorySlash off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ /$1.php [NC,L]
来源:https://stackoverflow.com/questions/38193414/htaccess-identical-folder-and-file-name