字符串中带有“+”的重定向规则不起作用

Redirect rules with "+" in the string not working

我正在使用 Nginx 并在 .conf 中为站点设置了一些重定向规则,例如

if ($query_string ~ "Search=shelving"){ rewrite .*$ /shelving.html? redirect; }

所以任何 url 与 "Search=shelving" 将重定向到 /shelving.html

这很好用,但我有其他规则在字符串中有 +,但不起作用,例如

if ($query_string ~ "Search=metal+shelving"){ rewrite .*$ /shelving.html? redirect; }

这是行不通的,我认为 + 正在破坏它,这附近有什么吗?

谢谢

编辑:

我希望重定向的 url 示例是:

https://example.com/SearchResults.aspx?Search=metal+shelving

https://example.com/shelving.html

我会这样写:

map $arg_search $redirect_url {
  default "";
  "metal shelving" /shelving.html;
  "metal+shelving" /shelving.html;
  "metal%2bshelving" /shelving.html;
  "metal%2Bshelving" /shelving.html;
}

server {
  ...
  if ($redirect_url) {
    return 301 $redirect_url;
  }
  ...
}

只是为了涵盖所有可能的 url 编码。

你应该像这样更新你的 nginx 规则

if ($query_string ~ "Search=metal\+shelving"){ rewrite .*$ /shelving.html? redirect; }