WenRou's Blog

新浪微薄腾讯微薄

最新碎语:测试图片碎语哦

您的位置:WenRou's Blog >工作> 搞定301转向

搞定301转向

比如我想要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 。

---

转载请注明本文标题和链接:《搞定301转向

分享到:

发表评论

54 + 5 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交