Linux 将所有url重写为除nginx中的url之外的其他url
我要重定向Linux 将所有url重写为除nginx中的url之外的其他url,linux,redirect,nginx,Linux,Redirect,Nginx,我要重定向 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) 我尝试了以下配置并实现了前三个
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;
}
有人能帮助我进行此配置吗?
位置~*^/
匹配以/
开头的任何URI,即尚未匹配早期正则表达式位置规则的任何URI
要仅匹配URI/
而不匹配其他内容,请使用$
运算符:
location ~* ^/$ { ... }
或者更好,精确匹配位置块:
location = / { ... }
有关更多信息,请参阅。精确匹配位置块对我很有用。非常感谢。