Apache rewriterule与正则表达式

时间:2012-03-01 22:38:49

标签: apache mod-rewrite

我正在尝试重写这样的多个页面......

http://subdomain.domain.com/index.php?action=printpage;topic=12345.67

对此...

http://subdomain.domain.com/index.php/topic,12345.67.html

我尝试使用...

失败了
RewriteRule ^index\.php\?action=printpage;topic=([0-9]+)\.([0-9]+)$ http://subdomain.domain.com/index.php/topic,$1.$2.html [R=302]

Apache服务器和我的其他不相关的重写工作正常。有人可以提供任何建议吗?感谢。

1 个答案:

答案 0 :(得分:1)

您无法与RewriteRule中的查询字符串匹配,您需要使用RewriteCond和后退引用:

RewriteCond %{QUERY_STRING} ^action=printpage;topic=([0-9]+)\.([0-9]+)$
RewriteRule ^index\.php$ http://subdomain.domain.com/index.php/topic,%1.%2.html? [R=302]
相关问题