URL Rewrites ala Nginx Location Rewrite

I’ve been going through the docs and playing about with the request-transform plugin but I think I’m mixing use cases.

Whats the best practice for URL rewrites in Kong ie. api.external.tld/v1/resource -> internal.service/v1_resource? Is this to be kept in the Openresty server config definition as a location rewrite or can it be handled by Kong so that everything is kept together in the DB?

Any direct links to the docs that covers this would be much appreciated.


Using the request-transformer plugin is a good way to modify the upstream request.

To do so in a custom plugin, see this post. (and why there isn’t any extensive documentation about it.)

Thanks. Would you have an example of doing a URL rewrite using the request-transformer plugin? With the rule options of querystring, header & body it’s not obvious where the rules would go.

Likewise, going through the code for the plugin I noticed that for querystrings it’s using ngx.req.set_uri_args to parse the arguements. But somewhere I can’t find seems to be preventing querystring values from being modified. Is that a limitation of the plugin or lua-nginx-module? My goal with querystrings would be to replace config rules like:

if ($args ~* (.*)(some_qs=blah)(.*)) {
  set $args $1some_qs=foo$3;

Cheers for your help.

Hello @samgaw did you ever find a solution to your problem? I’m in the same boat and the aforementioned plugin doesn’t seem the solution to my problem, it seems to work just with params (body for POST, querystring for GET) and not paths