[英]Mod_Rewrite hiding directory
我對mod_rewrite規則沒有什么疑問。 該規則似乎有效,但是阻止了對目錄及其文件的訪問。
這是我想要完成的
www.example.com/about-us/ *** Parent rule
www.example.com/about-us/our-mission.html *** child rule
雖然,我的規則是做到這一點,但是阻止了對服務器上物理文件和目錄的訪問。
在同一台服務器上,我具有管理界面,用戶需要訪問此界面才能進行更改...
www.example.com/manage/dash.php
當我嘗試訪問目錄/ manage或其目錄文件時,我被重定向到404頁面,該頁面是由子重寫規則生成的。
當我注釋掉子重寫規則時,我可以訪問提到的這些規則,但是使用子規則,訪問將被阻止。
請在下面查看我的重寫代碼,並幫助我確定問題所在。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This rule will rewrite url to the main page www.example.com/about-us
RewriteRule ^([^/]+)/?$ index.php?get_parent=$1 [L]
#This rule will rewrite url to the secondary url www.example.com/abou-us/our-mission.html
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?get_parent=$1&get_child=$2 [L]
謝謝。
您還需要從第二個RewriteRule中排除文件/目錄。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This rule will rewrite url to the main page www.example.com/about-us
RewriteRule ^([^/]+)/?$ index.php?get_parent=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This rule will rewrite url to the secondary url www.example.com/abou-us/our-mission.html
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?get_parent=$1&get_child=$2 [L]
這似乎很公平,因為您的網址www.example.com/manage/dash.php與正則表達式匹配。 在第一個規則的末尾有[L]時,第二個規則不再使用2個條件
您也應該添加一個不匹配的模式(請參閱文檔 )
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
在這里,我們認為文件/manage/dash.php確實存在。
希望對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.