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>";
        }
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM