繁体   English   中英

Mod_Rewrite隐藏目录

[英]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.

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