In one of my location rules, I am trying to rewrite the URL as such:
rewrite ^ $topicredirecturi?$args permanent;
$topicredirecturi
is calculated in a map file, mapping for example a URL such as
http://www.topics.com/companies/cit-group-inc/index.html
to
http://www.topics.com/companies/cit_group_inc/index.html
When I make my request with URL parameters such as:
http://www.topics.com/companies/cit-group-inc/index.html?rss=1
I get the following rewritten URL with duplicate params:
http://www.topics.com/companies/cit_group_inc/index.html?rss=1&rss=1
Similarly, the URL
http://www.topics.com/companies/cit-group-inc/index.html?rss=1&bob=2
gets rewritten to
http://www.topics.com/companies/cit_group_inc/index.html?rss=1&bob=2&rss=1&bob=2
Anyone know what might be going on here?
Nginx appends the query string automatically if there are other get parameters in the rewritten URL. If you're adding $args
yourself you should add a ?
(question mark) at the end of the rewritten URL to avoid having duplicate parameters.
The correct way of doing a redirect with query string is this:
rewrite ^(...)$ /destination$is_args$args? [permanent|redirect];
where $is_args
contains a ?
iff the query string is not empty, and $args
is the query string itself; the question mark at the end requests to nginx to not add the query string again.
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