Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在nginx重写中使用$args导致URL参数重复_Nginx_Rewrite_Query String - Fatal编程技术网

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

在nginx重写中使用$args导致URL参数重复,nginx,rewrite,query-string,Nginx,Rewrite,Query String,在我的一个位置规则中,我试图将URL改写为: rewrite ^ $topicredirecturi?$args permanent; $topicredirecturi在映射文件中计算,映射例如URL,如 http://www.topics.com/companies/cit-group-inc/index.html 到 当我使用URL参数进行请求时,例如: http://www.topics.com/companies/cit-group-inc/index.html?rss=1 我获

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

rewrite ^ $topicredirecturi?$args permanent;
$topicredirecturi
在映射文件中计算,映射例如URL,如

http://www.topics.com/companies/cit-group-inc/index.html

当我使用URL参数进行请求时,例如:

http://www.topics.com/companies/cit-group-inc/index.html?rss=1
我获得了以下重写的URL,其中包含重复的参数:

http://www.topics.com/companies/cit_group_inc/index.html?rss=1&rss=1
类似地,URL

http://www.topics.com/companies/cit-group-inc/index.html?rss=1&bob=2
被重写为

http://www.topics.com/companies/cit_group_inc/index.html?rss=1&bob=2&rss=1&bob=2

有人知道这里可能发生了什么吗?

Nginx会在重写的URL中有其他get参数时自动追加查询字符串。如果要自己添加
$args
,则应在重写的URL末尾添加
(问号),以避免重复参数

使用查询字符串执行重定向的正确方法如下:

rewrite ^(...)$ /destination$is_args$args? [permanent|redirect];
其中
$is_args
包含一个
如果查询字符串不是空的,并且
$args
是查询字符串本身;末尾的问号请求nginx不再添加查询字符串

rewrite ^(...)$ /destination$is_args$args? [permanent|redirect];