在nginx中重定向期间重命名特定的查询参数

问题描述:

我想要重定向类似/catalogsearch/result/?q=[keyword]的URL到/products?keyword=[keyword]。遵循规则有什么问题?在nginx中重定向期间重命名特定的查询参数

location ~ /catalogsearch/result/?q=(.*) { 
    rewrite^/products?keyword=$1 permanent; 
} 

后它(查询字符串)的?和任何不能由locationrewrite指令中使用的归一化URI的一部分。

假设只有一个参数,您可以使用$arg_ family of variables来访问它。

location = /catalogsearch/result/ { 
    return 301 /products?keyword=$arg_q; 
}