2013-10-28 105 views
1

我正在使用mod_rewrite重写我的链接,如下所示。我定义了一个重定向从/test/1234_5678_.../test.php?id=1234如下:.htaccess:重写规则模式匹配

RewriteRule test/(.*)_(.*)$ test.php?id=$1 

它的工作原理perfectely。现在我想添加以下重定向:/test/1234_5678_.../print/test.php?id=1234&print。因此,我在上面添加了以下行。重定向不起作用,似乎只有第二条规则适用。我在模式匹配上做了什么错误?是否可以有一个以上的下划线并且我只在模式中使用了一个?

RewriteRule test/(.*)_(.*)/print$ test.php?id=$1&print 
RewriteRule test/(.*)_(.*)$ test.php?id=$1 

回答

1

两个规则的工作对我很好,但你可能要在第一组到([0-9]+)([^_]+),而第二组更改为[^/]+,并添加一些L标志:

RewriteRule test/([^_]+)_([^/]+)/print$ test.php?id=$1&print [L] 
RewriteRule test/([^_]+)_([^/]+)$ test.php?id=$1 [L] 
+0

这weired。这不适合我。如果我无法修复它,我会仔细检查并尝试提供一个示例。 – user1000742