How to write Nginx301 redirect
滿天的星座
滿天的星座 2017-05-16 17:22:58
0
3
643

Nginx.
Original URL:
http://www.domain name.com/news/aaa.html
http://www.domain name.com/product/aaa/bbb/xxx.html
It is necessary to redirect the web pages in the two directories /news/ and /product/ to the following URL:
http://www.domain name.com/old/news/aaa.html
http://www.domain name.com/old/product/aaa/bbb/xxx.html

滿天的星座
滿天的星座

reply all(3)
大家讲道理
rewrite ^/(news|product)/(.*)$ /old// permanent last;

Put it in the server block. Just written it casually, not tested.

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

The key is permanent

Subdirectory jump:

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

rewrite

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template