删除不需要的参数

Remove unwanted parameter

我正在尝试从下面的 url 中删除参数“?status=OK”。

当前:

https://example.com/download/d2e9cc4f-f7df-4ebd-a0e4-7836c8013075?status=OK

目标:

https://example.com/download/d2e9cc4f-f7df-4ebd-a0e4-7836c8013075

Nginx:

location /download/ {
    rewrite ^(/download/.*)?$  permanent;
}

不幸的是,上面的方法不起作用。

查询字符串不是 locationrewrite 语句用来测试正则表达式的规范化 URI 的一部分。

您可以使用 if ($args) { ... } 检查是否存在任何参数,或者仅使用 if ($arg_status) { ... } 检查是否存在 status= 参数。

例如:

location /download/ {
    if ($args) { return 301 $uri; }

    ...          # do something with the corrected URI
}

rewrite语句也可以用rewrite ^(.*)$ ? permanent删除查询字符串,但return语句似乎更简单。请参阅 this caution 关于 if.

的用法