zoukankan      html  css  js  c++  java
  • apache与nginx的rewrite规则问题。

    尽管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;

    就需要,不知其它类型是否这样?!
  • 相关阅读:
    .Net 并发写入文件的多种方式
    变量命名神器——CODELF
    Python打包发布
    python工具——NumPy
    python工具——Pandas
    没事早点睡
    python工具——pixellib
    Tensorflow在Windows下使用踩坑
    python工具——Tesseract
    python工具——wordcloud
  • 原文地址:https://www.cnblogs.com/sumsung753/p/4083466.html
Copyright © 2011-2022 走看看