Is there easy way to HTTP redirect (301 Moved Permanently) https://api.organization.com/ to https://apiinfo.organization.com/ ?
It would be very easy to provide a plugin for that. E.g. take this as a base:
Name it to e.g. request-redirection. Make some changes to Schema. And then in handler call e.g. this:
But I think this is a quick win, so we may create it.
Request termination doesn’t support setting Location
header as of now, so you need to revert meta-refresh
or javascript
with that.
I actually do this already by using the response-transformer plugin to add a the Location header and request-termination to specify the status code and a body, works a treat! I’m using it a few places
@Adam_Curtis How exactly do you do that? iirc the request-termination runs in the access phase, the response transformer a lot later.
What version of Kong are you using?
@Tieske I’m using 0.11.2, it definitely seems to work, I’ve just checked with curl and the Location header is present!
So heres the config:
response-transformer:
add.headers = "Location:https://jumplead.com/join-us"
request-termination:
status_code = 301
content_type = "text/html; charset=UTF-8"
body = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href=\"https://jumplead.com/join-us\">here</a>.</p> <hr> </body></html>"
You can verify with curl: curl -v https://join-us.jumplead.com
Thanks! Works with Kong 0.11.2, request-termination and response-transformer combination.