gpt4 book ai didi

redirect - 在 nginx 重定向中将未知子域中的下划线替换为破折号

转载 作者:行者123 更新时间:2023-12-02 19:08:20 25 4
gpt4 key购买 nike

我收到的网址如下所示:

https://some_sub_domain.whatever.com

需要重定向到:

https://some-sub-domain.whatever.com

我不知道子域是什么(它们是用户名)。

虽然我需要替换子域的下划线,但我需要保留其他下划线:

https://some_sub_domain.whatever.com/hey_there_underscore

应该重定向到:

https://some-sub-domain.whatever.com/hey_there_underscore

最佳答案

下面是通过lua重写的方法:

location / {
rewrite_by_lua '
if string.find(ngx.var.host, "_") then
local newHost, n = ngx.re.gsub(ngx.var.host, "_", "-")
ngx.redirect(ngx.var.scheme .. "://" .. newHost .. ngx.var.uri)
end
';
proxy_pass http://my_backend;
proxy_set_header Host $host;
}

关于redirect - 在 nginx 重定向中将未知子域中的下划线替换为破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14567634/

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