RedirectRegex

    The RedirectRegex redirects a request using regex matching and replacement.

    Docker

    Kubernetes

    1. # Redirect with domain replacement
    2. apiVersion: traefik.containo.us/v1alpha1
    3. metadata:
    4. name: test-redirectregex
    5. spec:
    6. redirectRegex:
    7. regex: ^http://localhost/(.*)
    8. replacement: http://mydomain/${1}

    Consul Catalog

    1. "traefik.http.middlewares.test-redirectregex.redirectregex.replacement": "http://mydomain/${1}"
    2. }

    Rancher

    File (YAML)

    1. # Redirect with domain replacement
    2. http:
    3. middlewares:
    4. test-redirectregex:
    5. redirectRegex:
    6. replacement: "http://mydomain/${1}"

    File (TOML)

    Configuration Options

    Set the option to true to apply a permanent redirection.

    Tip

    Regular expressions and replacements can be tested using online tools such as 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.

    The replacement option defines how to modify the URL to have the new target URL.

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