ReplacePathRegex
The ReplaceRegex replaces the path of a URL using regex matching and replacement.
The ReplacePathRegex middleware will:
- Replace the matching path with the specified one.
- Store the original path in a
X-Replaced-Path
header.
tip
Regular expressions and replacements can be tested using online tools such as Go Playground or the Regex101.
When defining a regular expression within YAML, any escaped character needs to be escaped twice: example\.com
needs to be written as example\\.com
.
Configuration Options
regex
Field | Description |
---|---|
regex | The regex option is the regular expression to match and capture the path from the request URL. |
replacement
warning
Care should be taken when defining replacement expand variables: $1x
is equivalent to ${1x}
, not ${1}x
(see Regexp.Expand), so use ${1}
syntax.
Field | Description |
---|---|
replacement | The replacement option defines the replacement path format, which can include captured variables. |
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-replacepathregex
spec:
replacePathRegex:
regex: ^/foo/(.*)
replacement: /bar/$1