Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mod rewrite mod_重写问题_Mod Rewrite - Fatal编程技术网

Mod rewrite mod_重写问题

Mod rewrite mod_重写问题,mod-rewrite,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&a

在.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]标志

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


非常感谢,Jason

/author/Jim+Jones/28不应该被这些规则中的任何一个抓住,因为您的两个规则都没有捕捉到以/开头的URL,并且在您的正则表达式开头的“^”清楚地表明,对于第一个规则,它必须以“author/”开头(注意不/开头)

更新: 我认为正在发生的是,像myblog.com/author/Jim+Jones/28这样的请求被重写了两次。先按第一条规则,然后按第二条规则。如果是这样的话,你需要使第二条规则更加严格。例如,不要让它重写包含author.php的请求

更新2: 好的,那么在你的情况下最好的方法是为第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]

谢谢gligoran,我错过了示例中的重写基础。我已经更新了规则…更新:“如果是这样的话,你需要使第二条规则更加严格。”这就是我想要做的??我该怎么做?顺便说一句:你的第二个重写规则有一个小错误。它重写的URL也缺少?在主要部分和查询字符串之间。BTW 2:第二条规则中的:[^/index.php]您想做什么?类似[^chars]的字符类意味着这些字符中的非字符将被匹配。你所做的是第一组不能以chars/,i,n,d,e,x,,,p和h结尾。这只取决于性格。正则表达式很难使用,使用Expresso()之类的工具会有很大帮助,因为它提供了一个树来解释发生了什么。