简体   繁体   English

Mod_Rewrite隐藏目录

[英]Mod_Rewrite hiding directory

I am having little issue with mod_rewrite rule. 我对mod_rewrite规则没有什么疑问。 The rule seem to be working but blocks access to the directory and its files. 该规则似乎有效,但是阻止了对目录及其文件的访问。

Here is what i want to accomplish 这是我想要完成的

www.example.com/about-us/  *** Parent rule

www.example.com/about-us/our-mission.html *** child rule

Although, my rule is accomplishing this but blocking access to the physical file and directory on the server. 虽然,我的规则是做到这一点,但是阻止了对服务器上物理文件和目录的访问。

On the same server i have admin interface where user need to access to make changes... 在同一台服务器上,我具有管理界面,用户需要访问此界面才能进行更改...

www.example.com/manage/dash.php

When i attempt to access the directory /manage or its is files, i am redirected to 404 page that is a redirected generated by the child rewrite rule. 当我尝试访问目录/ manage或其目录文件时,我被重定向到404页面,该页面是由子重写规则生成的。

When i comment out the child rewrite rule i am able to access these mentioned but with child rule, access is blocked. 当我注释掉子重写规则时,我可以访问提到的这些规则,但是使用子规则,访问将被阻止。

Please see my rewrite code below and help me identify the issue. 请在下面查看我的重写代码,并帮助我确定问题所在。

 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]

Thank you. 谢谢。

You will need to exclude files/dirs from 2nd RewriteRule as well. 您还需要从第二个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]

This seems pretty fair, as your url www.example.com/manage/dash.php is matching the regexp. 这似乎很公平,因为您的网址www.example.com/manage/dash.php与正则表达式匹配。 With the [L] at the end of the first rule, the 2 conditions are not used anymore for the second rule 在第一个规则的末尾有[L]时,第二个规则不再使用2个条件

You should add a non matching pattern too (see documentation ) 您也应该添加一个不匹配的模式(请参阅文档

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

Here we supposed that the file /manage/dash.php really exists. 在这里,我们认为文件/manage/dash.php确实存在。

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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