Ok, I just want to add parameters whenever /search is called:
rewrite ^/search$ /search?foo=bar redirect;
Seems simple logic but it leads to endless loop because nginx takes the parameters separately and so the $ isn't working anymore. /search?foo=bar trigger it again and again and again because it stupidly matches.
So is there any working solution without touching the $args?
(I want to use regex because the matching rule is a bit more complicate but basically its what I want)
According to the nginx wiki, "rewrite operates only on path, not parameters."
So maybe the key is to rewrite only if the parameter is not found.
if ($args !~ "(^|&)foo=") {
rewrite ^/search$ /search?foo=bar redirect;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With