麻烦2 RewriteRule

时间:2016-11-24 09:30:54

标签: apache .htaccess mod-rewrite rewriting

我的htaccess中有两个Rewriterule有麻烦

RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)/?$ viewauthor.php?lg=$1&cat=$2&nameauthor=$3&id=$4 [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)/?$ viewbook.php?lg=$1&cat=$2&namebook=$3&id=$4 [NC,L]

我无法访问第二个重写因为它是相似的 看看我在哪个页面。我把echo $_SERVER['QUERY_STRING'];放在这两页中。

当我删除标记[NC,L]时,我会访问第二个重写,但lg=viewauthor.php代替lg=en

1 个答案:

答案 0 :(得分:0)

您需要一个前缀来区分,但是您没有捕获它,它只是用于匹配规则:

RewriteRule ^author/(.*)/(.*)/(.*)/([0-9]+)/?$ viewauthor.php?lg=$1&cat=$2&nameauthor=$3&id=$4 [B,NC,L]
RewriteRule ^book/(.*)/(.*)/(.*)/([0-9]+)/?$ viewbook.php?lg=$1&cat=$2&namebook=$3&id=$4 [B,NC,L]

现在将您的网址设为/author/foo/far/faz/1/book/boo/bar/baz/2。请注意添加B标志。