htaccess identical folder and file name

偶尔善良 提交于 2020-02-04 06:33:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!