我想使用 Kong 的 request-termination & response-transformer 插件实现一个简单的重定向。插件大部分都有效,但我在处理查询参数时遇到了问题。
我的插件配置与此类似(注意:我在无 DB 模式下使用 Kong):
services:
- name: my-redirects
url: http://localhost:8080/
routes:
- name: redirect-route
paths:
- /context$
- /$
plugins:
- name: request-termination
config:
status_code: 301
message: Redirect to main page...
- name: response-transformer
config:
add:
headers:
- Location:/context/
我想获得以下行为:
- 用户访问 http://localhost:8000/ -> 重定向到
/context/
- 用户访问 http://localhost:8000/context -> 重定向到
/context/
- 用户访问 http://localhost:8000/?param=value -> 重定向到
/context/?param=value
- 用户访问 http://localhost:8000/context?param=value -> 重定向到
/context/?param=value
基本上/
和/context
请求都应该被重定向到/context/
(最后一个斜杠),但查询参数应该被保留。
如何修改配置:
add:
headers:
- Location:/context/
包括在请求中匹配的查询参数?我希望能够做类似的事情:
add:
headers:
- Location:/context/$query_params