I've seen quite similar posts but not exactly what I'm looking for. I am trying to implement a nginx rewrite which should modify the content of a get variable. The result is always 404 not found and I cannot understand what is wrong. More specifically, I want:
https://mydomain.tld/resellers/view.php?id=1&url=https://market.tld to be rewritten to: https://resellers.mydomain.tld/view.php?id=1&url=101
So, there are 2 modifications:
- mydomain changes to resellers.mydomain
- url content changes to numeric
The config that I think should work is:
location ~ /resellers {
rewrite ^/resellers/view.php?id=1&url=https://market.tld https://resellers.mydomain.tld/view.php?id=1&url=101;
}
Because there will be multiple combinations of links, regarding the id and url variables, would it be better to use rewrite maps? What I mean is that I want to be explicit when creating rules for the id and url variables and not use wildcards, as in more simple rewrite rules.
I hope that someone has been in a situation like this before, to shed some light. Thank you very much for your time.
The regular expression of the
rewrite
directive cannot match the arguments part of the URL.If you are attempting to redirect a single URI, use the
location =
syntax. See this document for details.Assuming that there are more than one mapping for the
url
parameter, themap
is a good solution. See this document for details.For example:
Note that the
map
block is located outside of theserver
context.