首页 > Web开发 > 详细

Apache Rewrite匹配问号的问题

时间:2016-08-23 11:35:07      阅读:164      评论:0      收藏:0      [点我收藏+]

  在写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

Apache Rewrite匹配问号的问题

原文:http://www.cnblogs.com/shenxinpeter/p/5798411.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!