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/cushion.html
example.com/shop/?2008=1&vare_id=10553&variant_id=2232 > /garden/cushion/black.html
I tried with the following
Simple rewrite
rewrite /shop/?category_id=27 /garden/cushion.html permanent;
Location rewrite
location /shop/?category_id=27 {
rewrite /shop/?category_id=27 /garden/cushion.html;
}
And with location where I commented special signs
location /shop/\?category_id=27 {
rewrite /shop/\?category_id=27 /garden/cushion.html;
}
I add them directly into server {...}
in the nginx configuration
Firstly, anything from the
?
onwards is the query string and is not part of the normalised URI used by therewrite
andlocation
directives.One way to achieve your objective is to test the
$request_uri
variable using amap
directive.For example:
See this document for more, and this caution on the use of
if
.