不要使用
我想在内部将几个位置/customers/foo?bar=2
重写到位于/blah
的nginx配置中的现有位置,这样就好像请求是到/blah/customers/foo?bar=2
一样。
location /blah {
# View in fiddler
proxy_pass http://127.0.0.1:8888/;
# Lots of config here I don't want to repeat everywhere else
}
location /customers/ {
rewrite ^/customers/(.*) /blah/customers/$1$is_args$args;
}
location /other/ {
rewrite ^/other/(.*) /blah/other/$1$is_args$args;
}
# etc...
Nginx正在用编码为路径/blah/customers/foo%34bar=2
的查询字符串重写URL。
rewrite ^ /blah$request_uri;
也发生了同样的情况。它将?
编码为%3F
,有效地混淆了URL。
如果我执行客户端重定向rewrite ^ /blah$request_uri permanent;
,URL是正确的,并且包含?
,但我希望在我的NGINX配置中有内部重定向。
$is_args$args
,因为rewrite
指令会自动附加任何现有的查询字符串。
例如:
rewrite ^/customers/(.*) /blah/customers/$1 last;
虽然,我更喜欢:
rewrite ^(.*)$ /blah$1 last;
甚至:
rewrite ^ /blah$uri last;