admin avatar

Nginx 域名转向从www 到裸域名

🕧 by admin

目的:把域名www.domain.com 转到domain.com 下面的两个代码可以实现

1
2
3
4
5
if ($host ~* www\.(.*))
{
    set $host_without_www $1;
    rewrite ^(.*)$ http://$host_without_www$1 permanent;
}
1
2
3
4
5
6
# Redirect www to non-www
server
{
    server_name ~^www\.(?P<domain>.+)$;
    rewrite ^ http://$domain$request_uri permanent;
}
摘菜 http://blog.sramana.in/www-to-non-www-in-nginx

💘 相关文章

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.3 Processed in 0ms