RedirectRegex
RegexRedirect redirect a request from an url to another with regex matching and replacement.
apiVersion: traefik.containo.us/v1alpha1
metadata:
name: test-redirectregex
spec:
redirectRegex:
regex: ^http://localhost/(.*)
"labels": {
"traefik.http.middlewares.test-redirectregex.redirectregex.replacement": "http://mydomain/${1}"
}
# Redirect with domain replacement
[http.middlewares]
[http.middlewares.test-redirectregex.redirectRegex]
replacement = "http://mydomain/${1}"
Configuration Options
Set the permanent
option to true
to apply a permanent redirection.
Warning
Care should be taken when defining replacement expand variables: $1x
is equivalent to ${1x}
, not ${1}x
(see ), so use syntax.
Regular expressions and replacements can be tested using online tools such as Go Playground or the .
The replacement
option defines how to modify the URL to have the new target URL.