Apache 用正则表达式重写规则

Apache 用正则表达式重写规则,apache,mod-rewrite,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/in

我正试图重写像这样的多页

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服务器和我的其他无关重写工作正常。有人能提供一些建议吗?谢谢。

您无法在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]