Nginx301重定向该怎么写


Nginx.
原来的URL:
http://www .域名.com/news/aaa.html
http://www .域名.com/product/aaa/bbb/xxx.html
需要把 /news/和/product/这2个目录下的网页重定向到以下URL:
http://www .域名.com/ old /news/aaa.html
http://www .域名.com/ old /product/aaa/bbb/xxx.html

301重定向 nginx

你妹你妹囧你妹 9 years, 9 months ago

rewrite

EX-蕾米朵露 answered 9 years, 9 months ago


 server {
    server_name www.xxx.com xxx.com;
    if ($host != 'www.xxx.com' ) {
        rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
    }
}

关键在 permanent

子目录跳转:


 location ~* ^/news/ {
    rewrite ^/news/(.*)$ http://www.xxx.com/old/news/$1 permanent;
}

一只小小D鸟 answered 9 years, 9 months ago


 rewrite ^/(news|product)/(.*)$ /old/$1/$2 permanent last;

放server块里。随手写的,没测试。

普通的小C answered 9 years, 9 months ago

Your Answer