【发布时间】:2019-03-27 17:59:43
【问题描述】:
您好,我们使用 nginx,由于系统发生变化,我们必须暂时 301 一些带有查询参数的 URL。我进行了很多搜索,但没有找到解决方案。
我们想要
- 用新值替换查询参数列表
- 进行多次替换
所以我们的 URI 应该重写为:
/page?manufacturer=812 **becomes** /page?brand=812
/page?manufacturer=812&color=11 **becomes** /page?brand=812&colour=33
/page?manufacturer=812&color=11&type=new **becomes** /page?brand=812&colour=33&sorttype=new
/page?color=11&type=new&manufacturer=812 **becomes** /page?colour=33&sorttype=new&brand=812
我知道如何搜索和替换。但是如何搜索和替换 多个 值呢?我正在尝试以下方法:
# Rewrite after attributes renaming
rewrite ^/(.*)manufacturer\=(.*)$ /$1brand=$2;
rewrite ^/(.*)color=(.*)$ /$1colour=$2;
rewrite ^/(.*)type=(.*)$ /$1sorttype=$2;
# there are about 20 more ...
我的问题:如何进行多次替换? (只要服务器执行“旧”命令,甚至不必重写)。我应该使用 map 语句还是有更好的技巧?
提前致谢!
【问题讨论】:
标签: nginx url-rewriting