簡體   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