[英]How to Have a File and Directory With Same Name
I have a website that I am hosting on an Apache web server, and I have some files that have the same names (without extensions) as some directories. 我有一个在Apache Web服务器上托管的网站,并且有些文件的名称与某些目录的名称相同(没有扩展名)。
I also have extensions removed in the .htaccess file: 我也删除了.htaccess文件中的扩展名:
#Remove .php from filenames
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
For example, I have a file called test.php and a directory called test. 例如,我有一个名为test.php的文件和一个名为test的目录。 When I go to http://redxtech.ca/test , it adds a slash to the URL and go to the contents of the directory test/.
当我转到http://redxtech.ca/test时 ,它会在URL上添加一个斜杠,然后转到目录test /的内容。
I know that by just typing in the .php at the end of the file name it would fix my problem, but I wish to not have the .php (or any extension at all) be there, just the file name without extension to go to the file, and with a slash to go to the directory. 我知道,只要在文件名的末尾输入.php即可解决我的问题,但是我希望那里没有.php(或任何扩展名),只是没有扩展名的文件名到文件,并带有斜杠转到目录。
Is there any way that I would be able to do this? 有什么办法可以做到这一点?
After a bunch of scouting this site, I have found an answer. 经过一堆的搜索,我找到了答案。
# Manually re-route test/ requests to test
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} test/$
RewriteRule ^(.*)/$ $1
# Hide extension
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The only thing is I have to do that separately for each directory that I wish to have this condition. 唯一的事情是我必须对希望具有这种条件的每个目录分别执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.