Home  >  Q&A  >  body text

How to write Nginx301 redirect

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

滿天的星座滿天的星座2713 days ago624

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 17:24:58

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

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

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-16 17:24:58

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

    reply
    0
  • 某草草

    某草草2017-05-16 17:24:58

    rewrite

    reply
    0
  • Cancelreply