Express Gateway Documentation
The Rewrite policy can rewrite the requested url or eventually redirect the current request with a specified status code.
This type of policy should generally be placed first in the policies list within a pipeline.
The Rewrite policy was the first policy to be built utilizing the plugin framework and not included as part of EG core.
To enable it, you need to install its plugin fist:
eg plugins install express-gateway-plugin-rewrite
policies: - rewrite
policies: - rewrite: - condition: name: pathmatch match: /tina/:code # Express Path action: rewrite: /status/:code redirect: 302 - condition: name: regexpmatch match: ^/js/(.*)$ action: rewrite: /src/js/$1
pathmatch: Express Path corresponding to the url pattern to look for
regexpmatch: RegExp corresponding to the url pattern to look for
- Express Path or RegExp corresponding to the url pattern to rewrite. The format should match the one used in the condition.
- When set to a number, it’ll redirect the request with the provided status code. If omitted, a rewrite action will be performed. You’re responsibile for the returned status code - there’s no validation.
In case you’re using Express Path as expression, you can use route parameters as well as multi segment matches: they will be forwarded correctly.
policies: - rewrite: - condition: name: pathmatch match: /api/:route* action: rewrite: /api/v1/:route redirect: 302
In this example, if the gateway is hit with an url such as
/api/users/nick, the user will be redirected to