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>";
        }
    }
}
原文地址:https://www.cnblogs.com/weilaibuxiangshuo/p/11370358.html