Apache Rewrite匹配问号的问题

  在写RewriteRule准备匹配url中的问号及后面的参数时,怎么弄都无法成功。正则的写法经过测试是正确的,问号也已经转义\?,可还是不行。

  百度查询了下,RewriteRule 不会去匹配问号?后面的字符串,如下:

QSA|qsappend

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.

Consider the following rule:

RewriteRule "/pages/(.+)" "/page.php?page=$1" [QSA]

With the [QSA] flag, a request for /pages/123?one=two will be mapped to /page.php?page=123&one=two. Without the [QSA] flag, that same request will be mapped to /page.php?page=123 - that is, the existing query string will be discarded.

 

所以,解决写法示例: 

RewriteRule   ^(\w{2,30})/(.+)$        index.php?controller=$1&action=$2 [QSA]

可以把 /member/select?id=10 重写成 /controller=member&action=select&id=10

posted @ 2016-08-23 10:57  shenxinpeter  阅读(1072)  评论(0编辑  收藏  举报