Abh*_*hek 4 regex nginx url-rewriting
我正在NGINX中使用此重写。
rewrite ^/test[^a-zA-Z0-9]{2}/?$ https://www.google.com permanent; // doesn't work
服务器无法启动,因为我min {2}在正则表达式中添加了重复项。当我像这样删除服务器时,服务器启动:
rewrite ^/test[^a-zA-Z0-9]/?$ https://www.google.com permanent; // this works
我已经尝试了两种{min,max}参数。使用min重复时出现的错误如下。
directive "rewrite" is not terminated by ";"
此重写的上下文是server。
有人可以告诉我我想念什么吗?是否需要安装一些模块才能正常工作?
我的产品NGINX版本是1.4,我在本地使用1.10尝试过。
这是设计使然-大括号在nginx.conf中是特殊的,如果用作正则表达式的一部分,则如果使用大括号,则必须在正则表达式周围使用双引号。
如果正则表达式包含“}”或“;”字符,则整个表达式应用单引号或双引号引起来。
例如,
rewrite "^/test[^a-zA-Z0-9]{2}/?$" https://www.google.com/ permanent;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
686 次 |
| 最近记录: |