Apache Rewrite匹配问号的问题

摘要:
在写RewriteRule准备匹配url中的问号及后面的参数时,怎么弄都无法成功。正则的写法经过测试是正确的,问号也已经转义?后面的字符串,如下:QSA|qsappendWhenthereplacementURIcontainsaquerystring,thedefaultbehaviorofRewriteRuleistodiscardtheexistingquerystring,andreplaceitwiththenewlygeneratedone.Usingthe[QSA]flagcausesthequerystringstobecombined.Considerthefollowingrule:RewriteRule"/pages/(.+)""/page.php?page=123-thatis,theexistingquerystringwillbediscarded.所以,解决写法示例:RewriteRule^/(.+)$index.php?

在写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匹配问号的问题》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇linux下导入导出MySQL数据库02 . Ansible高级用法(运维开发篇)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

nginx rewrite重写规则集合

本文根据网络搜索整理,不是原创 一.正则表达式匹配,其中: ~为区分大小写匹配 ~*为不区分大小写匹配 !~和!~* 分别为区分大小写不匹配及不区分大小写不匹配 . 匹配除换行符以外的任意字符 w 匹配字母或数字或下划线或汉字 s 匹配任意的空白符 d 匹配数字 匹配单词的开始或结束 ^匹配字...

Nginx Rewrite域名及资源重定向

一.正则匹配     1.匹配规则         ^$  标识符匹配后面跟-一个字符串。匹配字符串后将停止对后续的正则表达式进行匹配,如location ^~/images/,在匹配了/images/这个字符串后就停止对后续的正则匹配         =   精准匹配,如location=/,只会匹配url为/的请求         ~   区分大小写的...

Nginx设置404页面转发

Nginx设置404有很多用户都会遇到,在真正的使用中会有相当的问题解决方法。下面我们就来学些有关于Nginx设置404的解决方法。今天帮客户的Nginx设置404页面转发,按平常的写法 error_page 404 http://www.xx.com/?page-error.html;  这样写发现不能正常转跳,看来Nginx不能自动转义,加上转义后还是...

nginx出错:rewrite or internal redirection cycle

原配置:location / { rewrite ^/(.*).html$ /$1.html?mode=test last; error_page 404 = @nodejs; }修改后:location / {root /path/to/files;index index.html;#try_files $uri /ind...

nginx重定向

原文链接地址:http://seanlook.com/2015/05/17/nginx-location-rewrite/ location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的地址都以 /...

Apache Rewrite url重定向功能的简单配置

1.Apache Rewrite的主要功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范。平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等2.Apache Rewrite的配置Apache下的Rewrite配置主要有两种,一种是针对整个apache服务器的配置,此种配置的Rewrite规则是直接在httpd.conf下书写。配置步骤...