首页 > Web开发 > 详细

apache与nginx的rewrite规则问题。

时间:2014-11-08 16:36:08      阅读:228      评论:0      收藏:0      [点我收藏+]

尽管apache与nginx的rewirte模块都声明基于perl正则,但实际使用中还是有所不同,特别是nginx。

在apache中,在server全局配置的httpd.conf文件中使用全局变量%{…}判断并不稳妥,当我使用 %{REQUEST_FILENAME}判断请求是否为文件时就出错了。无论请求是否匹配文件,它都返回否。究其原因在手册中都有提示:

If used in per-server context (i.e., before the request is mapped to the filesystem) SCRIPT_FILENAME and REQUEST_FILENAME cannot contain the full local filesystem path since the path is unknown at this stage of processing. Both variables will initially contain the value of REQUEST_URI in that case. In order to obtain the full local filesystem path of the request in per-server context, use an URL-based look-ahead %{LA-U:REQUEST_FILENAME} to determine the final value of REQUEST_FILENAME.

它说,如果在server配置环境使用,SCRIPT_FILENAME和REQUEST_FILENAME变量并不能包含整个文件系统路径,因为这个处理阶段,这些路径还未知。这时,这两变量只是REQUEST_URI变量的初始值。为了获取系统路径,可以使用一个基于URL的变量%{LA-U:REQUEST_FILENAME}在前面做检测。

 

nginx有个非常奇怪的现象,在正则中点号(.)如果没有跟正则语意的语句并联在一起,它就是单纯的点号,如果你使用\转义反而会出错,因为它把\.看成是两个字符。例如:

rewrite /dd\.html /abc.php last;

替换的部分的点号并不需要转义。但如果是这样:

rewrite /dd\.html /.*\.php last;

就需要,不知其它类型是否这样?!

apache与nginx的rewrite规则问题。

原文:http://www.cnblogs.com/sumsung753/p/4083466.html

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