在nginx重写中使用$ args导致重复的URL参数

sir*_*rlo 4 rewrite nginx query-string

在我的一个位置规则中,我试图重写URL:

rewrite ^ $topicredirecturi?$args permanent;
Run Code Online (Sandbox Code Playgroud)

$topicredirecturi 在映射文件中计算,映射例如URL等

http://www.topics.com/companies/cit-group-inc/index.html
Run Code Online (Sandbox Code Playgroud)

http://www.topics.com/companies/cit_group_inc/index.html
Run Code Online (Sandbox Code Playgroud)

当我使用URL参数发出请求时,例如:

http://www.topics.com/companies/cit-group-inc/index.html?rss=1
Run Code Online (Sandbox Code Playgroud)

我得到以下带有重复参数的重写URL:

http://www.topics.com/companies/cit_group_inc/index.html?rss=1&rss=1
Run Code Online (Sandbox Code Playgroud)

同样,URL

http://www.topics.com/companies/cit-group-inc/index.html?rss=1&bob=2
Run Code Online (Sandbox Code Playgroud)

被改写为

http://www.topics.com/companies/cit_group_inc/index.html?rss=1&bob=2&rss=1&bob=2
Run Code Online (Sandbox Code Playgroud)

有人知道这里会发生什么吗?

iBo*_*obo 11

@Yirkha答案是错误的.Nginx的不查询字符串追加总是自动,但如果有在重写URL其他GET参数.如果您要$args自己添加,则应? 在重写的URL末尾添加(问号)以避免重复参数.

使用查询字符串进行重定向的正确方法是:

rewrite ^(...)$ /destination$is_args$args? [permanent|redirect];
Run Code Online (Sandbox Code Playgroud)

where $is_args包含?iff查询字符串不为空,并且$args是查询字符串本身; 最后的问号请求nginx不再添加查询字符串.