gpt4 book ai didi

linux - 将所有 url 重写为另一个 url,除了 nginx 中的一个

转载 作者:可可西里 更新时间:2023-11-01 11:51:36 24 4
gpt4 key购买 nike

我要重定向

https://dev.abc.com/ to https://uat.abc.com/

https://dev.abc.com/first to https://uat.abc.com/first

https://dev.abc.com/second to https://uat.abc.com/

https://dev.abc.com/third/ to https://dev.abc.com/third/ (Point the same)

我已经尝试使用以下配置并实现了前三个。但最后一个也重定向到 uat。在这种情况下,任何人都可以帮助我。

server {
listen 80;
server_name dev.abc.com;
root /var/www/

location ~* ^/first{
return 301 https://uat.abc.com$request_uri;
}

location ~* ^/second{
return 301 https://uat.abc.com;
}

location ~* ^/{
return 301 https://uat.abc.com$request_uri;
}

谁能帮我做这个配置?

最佳答案

location ~* ^/ 匹配以 / 开头的任何 URI - 这是尚未匹配早期正则的 任何 URI表达式定位规则。

要仅匹配 URI / 而不匹配其他任何内容,请使用 $ 运算符:

location ~* ^/$ { ... }

或者更好的是,精确匹配位置 block :

location = / { ... }

参见 this document了解更多。

关于linux - 将所有 url 重写为另一个 url,除了 nginx 中的一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47907074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com