我的 .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
现在我想要的是,我有像 css
这样的文件夹js
images
所以我没有 index.php
文件在那里,所以它列出了我的所有文件。我知道我可以在那里添加 index.php 文件并可以将用户重定向到我的根目录。但这是 TDS 的工作。有什么办法我可以在 .htaccess
中做点什么吗?以及在任何文件夹中的任何位置,如果无法找到 index.php
它带我到 index.php
的localhost
?
有什么办法可以做到吗。只是不想放index.php
在每个文件夹中限制其访问。
最佳答案
您基本上想要的是避免在没有索引文件时列出文件夹的所有文件。
您可以通过将其添加到 .htaccess 文件来实现此目的:
Options All -Indexes
关于php - 将用户从任何没有 index.php 的文件夹路由到某个文件,例如 : index. php |使用.htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17470534/