繁体   English   中英

从任何没有index.php的文件夹将用户路由到某个文件,例如:index.php | 使用.htaccess

[英]Route user to some file like: index.php from any folder which is not having index.php | using .htaccess

我的.htaccess文件中有此代码,可将用户路由到我的root/index.php文件

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

但是,这可以正常工作:因此,如果我要进入localhost/MyFolder/Xyz并且如果Xyz is not existing it takes me to localhost/index.php localhost/MyFolder/XyzXyz is not existing it takes me to localhost/index.php现在我想要的是,我有css js images类的文件夹,所以我没有那里有任何index.php文件,因此它列出了我的所有文件。 我知道我可以在那里添加index.php文件,并且可以将用户重定向到我的根目录。 但这是TDS的工作。 有什么办法可以在.htaccess中执行任何操作,以及在任何文件夹中的任何位置(如果无法找到index.php其带到localhost index.php

有没有办法做。 只是不想在每个文件夹中放置index.php来限制其访问。

您基本上想要的是避免在没有索引文件的情况下列出文件夹的所有文件。

您可以通过将其添加到.htaccess文件中来实现此目的:

Options All -Indexes

好的,我想您想要的只是从.htaccess文件中删除重写条件。 这些重写条件告诉Apache如果输入的路径是文件或目录的路径,则不要重定向。

RewriteEngine On

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

而已。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM