Skip to main content

RedirectRegex

The RedirectRegex redirects a request using regex matching and replacement.


Configuration Options

permanent

FieldDescription
permanentSet the permanent option to true to apply a permanent redirection.

permanent

Set the permanent option to true to apply a permanent redirection.

regex

FieldDescription
regexThe regex option is the regular expression to match and capture elements from the request URL.
note

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.

replacement

FieldDescription
replacementThe replacement option defines how to modify the URL to have the new target URL.
note

Care should be taken when defining replacement expand variables: $1x is equivalent to ${1x}, not ${1}x (see Regexp.Expand), so use ${1} syntax.

Example

Redirect with domain replacement
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-redirectregex
spec:
redirectRegex:
regex: ^http://localhost/(.*)
replacement: http://mydomain/${1}