WenRou's Blog
搞定301转向
2014-2-13 温柔哥
比如我想要vpshz.com直接跳转到www.vpshz.com

先进入/usr/local/nginx/conf/vhost 目录

你会看见以你域名命名的文件,比如 vpshz.com.conf

打开它,你会发现形如下面的代码



server

{

        listen       80;

        server_name vpshz.com www.vpshz.com; #server_name end

        index index.html index.htm index.php; #index end



        set $subdomain '';

        root  /home/wwwroot/vpshz.com/web$subdomain;

        include rewrite/amh.conf; #rewrite end

         include cc.conf;



编辑它。变成如下即可

server

{

        listen       80;

        server_name vpshz.com www.vpshz.com; #server_name end

        if ($host = 'vpshz.com') {

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

    }

        index index.html index.htm index.php; #index end



        set $subdomain '';

        root  /home/wwwroot/vpshz.com/web$subdomain;

        include rewrite/amh.conf; #rewrite end

         include cc.conf;





细心的你一定发现了,其实就是加了一段关键代码而已。如下:

        if ($host = 'vpshz.com') {

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

    }

复制代码



简单吧。 快去试试哦。

记得重启 nginx 。
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容