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