RedirectRegex

    RegexRedirect redirect a request from an url to another with regex matching and replacement.

    1. apiVersion: traefik.containo.us/v1alpha1
    2. metadata:
    3. name: test-redirectregex
    4. spec:
    5. redirectRegex:
    6. regex: ^http://localhost/(.*)
    1. "labels": {
    2. "traefik.http.middlewares.test-redirectregex.redirectregex.replacement": "http://mydomain/${1}"
    3. }
    1. # Redirect with domain replacement
    2. [http.middlewares]
    3. [http.middlewares.test-redirectregex.redirectRegex]
    4. 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.