nginx 利用return实现301跳转

第一种:

server
{
    location / {
        rewrite ^/(.*)$ http://www.baidu.com/$1 permanent;
    }
}

第二种:

server
{
    location / {
        return 301 http://www.baidu.com;
    }
}

第三种:

server
{
    location / {
        #default_type 指定显示格式,不可缺少,!-f /home/999 主要用于使条件为真,因为/home下并没有文件夹999
        default_type text/html;
        if (!-f /home/999) {
            return 200 "<html><script>window.location.href='http://www.baidu.com'</script></html>";
        }
    }
}

 

posted @ 2019-08-17 21:08  代码家园  阅读(9290)  评论(0编辑  收藏  举报