[英]Using regex capture groups from both the location and rewrite?
给出一些例子,例如:
location ~ ^/([\d]+)/ {
rewrite ^/[\d]+/([\d]+)/(.*)$ #replacement
proxy_pass https://httpbin.org/anything/$1/$2/$3 # ?
}
捕获组是什么? nginx 会取代它们吗? 合并他们? 在那种情况下我会有 3 个捕获组吗? 顺序是什么?
我不清楚如何引用上面 3 个捕获组中的每一个。
我引用捕获组的最后一个地方是在 proxy_pass 中。
每次 Nginx 计算另一个正则表达式时,数字捕获都会重置。
在评估proxy_pass
语句时,从location
表达式捕获的数字丢失了。 只定义$1
和$2
,它们取自rewrite
表达式。
要使捕获跨多个正则表达式持续存在,请使用(?<name>...)
语法为其命名。
例如:
location ~ ^/(?<name>[\d]+)/ {
rewrite ^/[\d]+/([\d]+)/(.*)$ ...;
proxy_pass https://httpbin.org/anything/$name/$1/$2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.