针对特定参数列表的Nginx重定向

针对特定参数列表的Nginx重定向,nginx,nginx-location,Nginx,Nginx Location,我有一个URL中一些过时参数的列表 arg1 arg2 arg3 ... argn 我需要将链接的查询部分中包含这些参数的任何请求重定向到特定站点 /page.html?arg1=sxx&arg2=uuu -> http://xxx.x.xxx.x /page.php?arg3= -> http://xxx.x.xxx.x /dir/dir/page/?arg2=111&& argn=xyyyy -> http://xxx.x.xxx.x /pa

我有一个URL中一些过时参数的列表

arg1
arg2
arg3
...
argn
我需要将链接的查询部分中包含这些参数的任何请求重定向到特定站点

/page.html?arg1=sxx&arg2=uuu  -> http://xxx.x.xxx.x
/page.php?arg3=  -> http://xxx.x.xxx.x
/dir/dir/page/?arg2=111&& argn=xyyyy  -> http://xxx.x.xxx.x
/page.html (is not redirected but matched to other existing rules in nginx)

你知道如何表达它吗?由于某些原因,location没有要由正则表达式匹配的参数

假设参数顺序是确定性的,您可以针对$request\u uri变量测试多个正则表达式

map
指令可用于列出多个规则和目的地

例如:

map $request_uri $redirect {
    default                          0;
    ~^/page\.html\?arg1=sxx&arg2=uuu http://xxx.x.xxx.x;
    ~^/page\.php\?arg3=              http://xxx.x.xxx.x;
    ...
}

server {
    ...
    if ($redirect) {
        return 301 $redirect;
    }
当然,您需要通过插入间隙(
*
)和单词边界(
\b
)来改进上面的正则表达式

有关
map
指令和关于
if
的使用,请参阅