mod_rewrite RewriteCond问题

时间:2010-11-17 07:19:06

标签: mod-rewrite

在我的.htaccess文件中,我有以下规则:

RewriteEngine on
RewriteBase /myblog.com/        
RewriteRule ^author/([^/]*)/?([^/]*)/?$ blog/author.php?author=$1&contactid=$2 [L]
       RewriteRule ^blog/([^/]*[^/index.php])/?([^/]*)/?([^/]*)/?$ blog/index.php blog=$1&category=$2&article=$3 [L]

我的问题是,像myblog.com/author/Jim+Jones/28这样的请求会被重定向到以下规则,即使我有一个[L]标志吗?

当URL中出现“/ author /”时,如何排除第二条规则?

非常感谢,杰森

1 个答案:

答案 0 :(得分:0)

/ author / Jim + Jones / 28不应该被这些中的任何一个抓住,因为你的规则都没有捕获以/开头的/和正则开头的^清楚的统计信息,对于第一条规则它必须以'author /'开头(注意开头没有/。)

更新: 我认为正在发生的事情是像myblog.com/author/Jim+Jones/28这样的请求被重写了两次。首先是第一条规则,然后是第二条规则。如果是这种情况,您需要使第二条规则更具限制性。不要让它重写其中包含author.php的请求。

更新2: 好的,那么在你的情况下最好的是为第二个子句添加一个条件:

RewriteEngine on
RewriteBase /myblog.com/        
RewriteRule ^author/([^/]*)/?([^/]*)/?$ blog/author.php?author=$1&contactid=$2 [L]

RewriteCond %{THE_REQUEST} !(author\.php)
RewriteRule ^blog/([^/]*[^/index.php])/?([^/]*)/?([^/]*)/?$ blog/index.php?blog=$1&category=$2&article=$3 [L]
相关问题