【转载】Apache Rewrite处理?问号后的请求参数

原文地址:http://www.netroby.com/html/2011/techdocument_0509/138.html

最近把一个项目从nginx转移到apache下面,有些rewrite规则?问号后面还有请求参数,apache rewrite规则需要改变一下才能适应这种需求。

最近把一个项目从nginx转移到apache下面,有些rewrite规则?问号后面还有请求参数,apache rewrite规则需要改变一下才能适应这种需求。

我们Rewrite后的地址 /sj/php?page=8, 实际地址 /search-job.php?key=php&page=8

在apache rewrite文档里面有一段介绍[QSA]参数,专门用来传递?后的请求参数到实际地址。

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa

 

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 /sj/(.+) /search-job.php?key=$1 [QSA]

apache的Rewrite规则可以实现很复杂的需求,但由此而来的问题就是它不是完全遵守RegEx正则表达式的规范。

nginx的rewrite很优雅,也比较简单,虽然它不能实现非常复杂的Rewrite,但应付日常应该足够。

我个人还是比较喜欢nginx的rewrite的写法,因为它是标准的regex正则表达式。

apache Rewrite规则不好调试,因为它很多时候是不标准的Regex.

原文地址:http://www.netroby.com/html/2011/techdocument_0509/138.html

参考文档:

http://wymsxty.blog.163.com/blog/static/77790858201121112725596/

http://man.chinaunix.net/newsoft/ApacheManual/misc/rewriteguide.html

http://lamp.linux.gov.cn/Apache/ApacheMenu/rewrite/rewrite_guide.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值