nginx的http和https 301跳转

来源:互联网 发布:windows聚焦图片在哪 编辑:程序博客网 时间:2024/05/17 02:24

HTTP 301跳转到带www域名方法

server {
        listen       80;
        server_name  example.org;
        return       301 http://www.example.org$request_uri;
    }
 server {
        listen       80;
        server_name  www.example.org;
        ...
    }   

HTTPS 301跳转到带www域名方法

server {
            listen 80;
            server_name www.domain.com;
            // $scheme will get the http protocol
            // and 301 is best practice for tablet, phone, desktop and seo
            return 301 $scheme://domain.com$request_uri;
    }
     
    server {
            listen 80;
            server_name domain.com;
            // here goes the rest of your config file
            // example 
            location / {
     
                rewrite ^/cp/login?$ /cp/login.php last;
                // etc etc...
     
            }
    }

原创粉丝点击