【发布时间】:2015-12-22 07:01:07
【问题描述】:
我在 Nginx 中有以下规则将特定 url 重定向到新 url
location /customer/my_info {
proxy_pass http://example.com/abc;
}
这很好用。我还有另一个 url,我不想被重定向,但它正在被重定向。
/customer/my_info_verify
需要添加什么规则才能只重定向完全匹配的 url?
【问题讨论】:
我在 Nginx 中有以下规则将特定 url 重定向到新 url
location /customer/my_info {
proxy_pass http://example.com/abc;
}
这很好用。我还有另一个 url,我不想被重定向,但它正在被重定向。
/customer/my_info_verify
需要添加什么规则才能只重定向完全匹配的 url?
【问题讨论】:
使用 = 修饰符定义 URI 和位置的精确匹配。如果找到完全匹配,则搜索终止。
location = /customer/my_info {
proxy_pass http://example.com/abc;
}
来源:http://nginx.org/en/docs/http/ngx_http_core_module.html#location
【讨论】:
/customer/my_info/ 不匹配。如果你也想匹配那个 URL,我会使用这样的正则表达式匹配:location ~* ^/customer/my_info/?$