Nginx rewrite urls with special characters

后端 未结 1 1914
渐次进展
渐次进展 2020-12-22 02:23

I just got a list of urls that needs to be rewritten into nginx

example.com/cms.php/inspiration?fullsize > /
example.com/shop/?category_id=27 > /garden         


        
相关标签:
1条回答
  • 2020-12-22 02:50

    Firstly, anything from the ? onwards is the query string and is not part of the normalised URI used by the rewrite and location directives.

    One way to achieve your objective is to test the $request_uri variable using a map directive.

    For example:

    map $request_uri $redirect {
        default                                     0;
        /cms.php/inspiration?fullsize               /;
        /shop/?category_id=27                       /garden/cushion.html;
        /shop/?2008=1&vare_id=10553&variant_id=2232 /garden/cushion/black.html;
    }
    server {
        ...
        if ($redirect) { return 301 $redirect; }
        ...
    }
    

    See this document for more, and this caution on the use of if.

    0 讨论(0)
提交回复
热议问题