我有一个网络服务器接受https://www.example.com/API/ooo/xxx
, https://www.example.com/API/aaa/bbb
, and https://www.example.com/API/xxx/yyy
... ETC。
现在我们想将上述任务重定向到https://www.example.com/ooo/xxx
, https://www.example.com/aaa/bbb
, and https://www.example.com/xxx/yyy
... ETC。
我尝试过使用rewrite
nginx 中的关键字:
location /API/ {
rewrite ^/API(.*)$ https://$host$1 redirect;
}
这适用于 GET 请求。但它将 POST 请求转换为 GET 请求。这是我不想要的。
如何在重定向时保留 http 方法/API/*
to /*
?
This post https://stackoverflow.com/questions/27795068/nginx-rewrite-post-data说我可以使用307
重定向。但rewrite
似乎不支持307
重定向。我不知道如何使用$1
正则表达式属性return
.
Use a return
陈述。您可以使用正则表达式location
块捕获要返回的 URI 部分。
例如:
location ~ ^/API(/.*)$ {
return 307 $1$is_args$args;
}
请注意,使用正则表达式location
指令,它在配置中的顺序很重要,因此您可能需要移动它。看这个文件 http://nginx.org/en/docs/http/ngx_http_core_module.html#location了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)