我正在阅读nginx的文档,但我不知道这个'(?U)'正在这个正则表达式中做什么.
http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_path_info
这是一个例子.脚本show.php接收字符串文章/ 0001作为参数.以下配置将正确处理路径拆分:
location ~ ^.+\.php {
(...)
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
(...)
}
Run Code Online (Sandbox Code Playgroud)
请求/show.php/article/0001将SCRIPT_FILENAME设置为/path/to/php/show.php,将PATH_INFO设置为/ article/0001.
这个正则表达式还不够?
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
Run Code Online (Sandbox Code Playgroud)
谢谢
?U在正则表达式中是不合适的.默认情况下,正则表达式使用"贪婪"模式.
在这种情况下,它是必要的.随着贪婪的比赛,这个以下的要求
/show.php/article/0001/another.php/something
Run Code Online (Sandbox Code Playgroud)
将脚本部分设置为
/show.php/article/0001/another.php
Run Code Online (Sandbox Code Playgroud)
这可能会导致意外的安全问题.
[ 更新 ]
nginx使用pcre regex:http://www.pcre.org/pcre.txt
Run Code Online (Sandbox Code Playgroud)(?U) default ungreedy (lazy)
| 归档时间: |
|
| 查看次数: |
1858 次 |
| 最近记录: |