2013-08-20 114 views
1

我对mod_rewrite规则没什么问题。该规则似乎正在工作,但阻止对目录及其文件的访问。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 

当我尝试访问目录/管理或它的是文件,我重定向到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] 

谢谢。

回答

0

您还需要从第二个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] 
+1

我明白了,所以这确实解决了这个问题,一旦规则结束,第一组排除便会被排除。没有想过这样。 – S01010011

0

这看起来相当公平,因为您的网址www.example.com/manage/dash.php与正则表达式匹配。使用[L]在第一个规则的结束,2个条件不再被用于第二规则

您应该添加非匹配模式太(见documentation

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

在这里,我们应该该文件/manage/dash.php确实存在。

希望它会帮助你。