我想在横幅中创建一个链接以重定向到两个页面之一。该链接指向subdomain.example.com/email
。如果浏览器语言是“de”,则转到www.example.de/banner
否则去www.example.com/banner
。我的 nginx conf 语言能力不好,但我知道任何德语浏览器语言的前两个字符都是“de”(参见https://www.metamodpro.com/browser-language-codes https://www.metamodpro.com/browser-language-codes)。没有其他语言有这个。
location /email {
if $http_accept_language === "de" { return 301 https://www.example.de/banner }
else { return 301 https://www.example.com/banner}
}
更清洁且可扩展的解决方案使用map
指示。
例如:
map $http_accept_language $redirect {
default https://www.example.com/banner;
~de https://www.example.de/banner;
}
server {
...
location /email {
return 301 $redirect;
}
...
}
See 这个文件 http://nginx.org/en/docs/http/ngx_http_map_module.html#map了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)