[英]nginx rewrite all subdomains to www
我试图找到正确的正则表达式将所有子域重写为www。
因此,例如将w7w.domain.com更改为www.domain.com
或alskdaslkdja.domain.com到www.domain.com
我尝试了很多事情,我的最后一次尝试是:
if ($host ~* (?!www\.)(.*))
{
set $host_without_www www.$1;
rewrite ^(.*)$ http://$host_without_www$1 permanent;
}
但这也不起作用。
我需要抓住这些,不能仅仅将wildcart重写为www.domain.com,因为我在该实例上提供了多个域。
有任何想法吗?
server {
listen xx.xx.xx.xx:80;
server_name www.example.com;
# ....
}
server {
listen xx.xx.xx.xx:80;
server_name example.com *.example.com;
rewrite ^ http://www.example.com$request_uri? permanent;
}
server {
# Prefix server wildcards are checked before regexes, so this
# will catch anything starting with www.
server_name www.*;
}
server {
# This should redirect anything that didn't match the first
# server to domain.tld
# I think this regex will capture the domain.tld
server_name ~(?<domain>[^.]+\.[^.]+)$
rewrite ^ http://www.$domain$request_uri? permanent;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.