Rewrites the path and query of requests, or answers them with a redirect. Acts on requests only.
The mappings are checked in order against the path and query, and the first one that matches is applied. Requests that match no mapping pass unchanged.
A rewrite does not change the call to a target URL with a path such as https://api.example.com/orders: that URL is sent as it is. Redirects work with any target.
See tutorials/routing/10-Rewrite-and-Redirect.yaml.
Security Hint
The expressions run on the request path. Overlapping quantifiers such as (.*)/(.*) can take a long time on crafted paths. See ReDoS Protection.
Example Configuration
api:
port: 2000
flow:
- rewriter:
- from: ^/store/(.*)
to: /shop/v2/$1
- from: ^/v1/(.*)
to: /store/$1
do: redirect_permanent
target:
url: https://api.predic8.de
api:
port: 2000
flow:
- rewriter:
- from: ^/store/(.*)
to: /shop/v2/$1
- from: ^/v1/(.*)
to: /store/$1
do: redirect_permanent
target:
url: https://api.predic8.de
Syntax
rewriter:
- <rewriter-map>rewriter: - <rewriter-map>