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 @   代码家园  阅读(9360)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示