2012-08-27 35 views
1
RewriteRule ^articles\.php\?id=([0-9]+)$ article-a$1.html [R=301,L] 

我想要所有链接像articles.php?id = 1211指向article-a {ID} .html,我该如何实现这一目标?这条规则有什么问题?我该如何使这个RewriteRule工作?

回答

3

不能匹配一个重写规则的查询字符串,你需要匹配对%{QUERY_STRING} VAR的条件,并使用%反向引用:

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ 
RewriteRule ^articles\.php$ article-a%1.html [R=301,L] 
+0

谢谢,不知道。 – Gamec

-1

Usefollowing,

RewriteRule ^articles.php?id=([0-9]+)$ article-a$1.html 
+0

绝对不是。您无法测试RewriteRule模式中的查询字符串。 –