1

我对 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 或其 is 文件时,我被重定向到 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]

谢谢你。

4

2 回答 2

0

您还需要从 2nd 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]
于 2013-08-20T21:59:45.400 回答
0

这似乎很公平,因为您的网址 www.example.com/manage/dash.php 与正则表达式匹配。在第一条规则的末尾使用 [L],第二条规则不再使用这两个条件

您也应该添加一个不匹配的模式(参见文档

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

这里我们假设文件 /manage/dash.php 确实存在。

希望它会帮助你。

于 2013-08-20T22:03:56.233 回答