简体   繁体   English

如何具有相同名称的文件和目录

[英]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. 唯一的事情是我必须对希望具有这种条件的每个目录分别执行此操作。

Answer found here . 这里找到答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 htaccess - 重写具有相同名称的目录的文件 - htaccess - Rewrite files that have a directory with the same name 如何打开另一个目录中具有相同名称的另一个文件? - How to open another file with the same name from another directory? 我怎样才能有一个同名的php文件和一个文件夹? - How can I have a php file and a folder with the same name? 如何在Nginx中使用route并具有与route相同的目录名? - How do I use route and have same directory name as route in nginx? 您如何回显多个具有相同名称的图像作为php文件名的一部分? - how do you echo multiple images that have the same name as part of the file name in php? 如何维护文件夹和文件同名但隐藏文件扩展名的网站? - How can I maintain a website where a folder and file have the same name but also hide the extension of that file? PHP如何遍历目录并将所有以相同字符串结尾的文件合并到该名称的单个文件中 - PHP How can I iterate over a directory and merge all files that end with same string in a single file of that name 如何显示具有相同名称的XML节点? - How to display XML nodes that have the same name? 不需要的Apache从目录重定向到同名文件 - Unwanted Apache redirect from directory to file with same name 当文件(扩展名已删除)和文件夹名称相同时,如何正确链接? - How do I link correctly when a file(extensions removed) and a folder have the same name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM