Mod_rewrite 重定向 url 问题

Mod_rewrite redirecting a url issue

我正在编写一个小 PHP 脚本。我使用 mod_rewrite 重定向了一些 URL,但是当我想将 http://localhost/mobile/g-phones-1.html?pn=2 转换为 http://localhost/mobile/phones.php?id=1&pn=2 时我发现了一个问题。

我用过这个

RewriteRule ^(.*)-phones-([^-]*)\.html?pn=([^-]*)$
phones.php?id=&pn= [L]

但是没用。请问我该如何解决?

RewriteRule ^(.*)-phones-([^-]*)\.html$ phones.php?id= [L,QSA]

QSA 标志用于附加当前查询字符串 (pn=2) 以重写 URL。 顺便说一句,你不能在重写规则中测试你的查询字符串,你必须使用 :

RewriteCond  %{QUERY_STRING}   ^REGEXP$