2013-10-28 106 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