咨询热线:4006-75-4006

售前:9:00-23:30    备案:9:00-18:00    技术:7*24h

如何配置Nginx 301重定向

2016-06-30 16:11:46 9510次

301重定向是很常见的需求,比如访问landui.com,自动跳到 www. landui.com。或者倒过来,访问 www. landui.com 跳到 landui.comNginx 中配置301 重定向,下面介绍下方法。

打开 nginx.conf 文件,找到你的 server 配置段:

server {

    listen       80;

    server_name  landui.com www. landui.com ;

    #server_name localhost;

    if ($host != 'www. landui.com ' ) {

        rewrite ^/(.*)$ http://www.landui.com landui.com /$1 permanent;

    }

}

如果访问的 URL 是不带 www 的地址,则跳到带 www URL 上面去。即让不带 www 的域名跳转到带 www 的域名。

或者单独为不带 www URL 单独设一条 server 规则:

 

server {

    server_name  landui.com;

    rewrite ^(.*) http://www.landui.com landui.com $1 permanent;

}

nginx.conf 上传,再 nginx -s reload 即可。


首页
最新活动
个人中心