nginx: How to mass permanent redirect from a given list?

后端 未结 2 1875
清歌不尽
清歌不尽 2020-12-05 08:03

I have about 400 url that will change in the new version and for some reasons I can\'t repeat the same type of url structure in the new website.

My question is, can

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 08:51

    Probably the easiest way to do that is to wrap map directive around your list. The configuration in this case would look like this:

    map $request_uri $new_uri {
        default "";
        /old/page1.html /new/page1.html;
        /old/page2.html /new/page2.html;
        ...
    }
    
    server {
        ...
    
        if ($new_uri != "") {
            rewrite ^(.*)$ $new_uri permanent;
        }
    
        ...
    }
    

提交回复
热议问题