The replication of the query parameters you see is the expected behavior of Nginx. To change this, do you need to add trailing ? to rewrite, as in:
server { listen 8080; server_name localhost; location / { if ($http_host !~* "^www\.") { rewrite (.*) http://www.$http_host$request_uri? permanent; } } }
See the documentation here .
If the replacement string contains new query arguments, the arguments of the previous query are added after them. If this is undesirable, placing a question mark at the end of the replacement line avoids adding them, for example:
rewrite ^ / users /(.*)$/ show? user = $ 1? last;
However, the configuration presented by Alexey Deryagin is a better and more efficient option for your desired type of redirection, because each request will be evaluated by the if block in the original configuration, regardless of whether it is needed or not.
source share