I want to implement a simple redirect using Kong's request-termination & response-transformer plugins. The plugins mostly works, but I have an issue with handling query parameters.
My configuration for the plugins is similar to this (note: I'm using Kong in DB-less mode):
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/
I want to obtain the following behaviour:
- User visits http://localhost:8000/ -> redirected to
/context/
- User visits http://localhost:8000/context -> redirected to
/context/
- User visits http://localhost:8000/?param=value -> redirected to
/context/?param=value
- User visits http://localhost:8000/context?param=value -> redirected to
/context/?param=value
Basically both /
and /context
requests should be redirected to /context/
(with a final slash) but query parameters should be preserved.
How can I modify the configuration:
add:
headers:
- Location:/context/
to include query parameters matched in the request? I expect to be able to do something like:
add:
headers:
- Location:/context/$query_params