• 【转载】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

  • 相关阅读:
    ES6 常用总结(前端开发js技术进阶提升总结)
    web前端之es6对象的扩展
    ES6数组及对象遍历的新增方法 entries(),keys() 和 values()
    关于日期
    最近遇到的几个小东西
    求模
    同步 异步请求的认识
    变量名和函数名声明提升
    机顶盒前端开发小结
    js节点使用 碎片节点
  • 原文地址:https://www.cnblogs.com/ainiaa/p/2248673.html
Copyright © 2020-2023  润新知