StripPrefixRegex

    Remove the matching prefixes from the URL path.

    Docker

    Kubernetes

    1. apiVersion: traefik.containo.us/v1alpha1
    2. kind: Middleware
    3. name: test-stripprefixregex
    4. spec:
    5. stripPrefixRegex:
    6. regex:
    7. - "/foo/[a-z0-9]+/[0-9]+/"

    Consul Catalog

    Marathon

    1. }

    File (TOML)

    1. [http.middlewares]
    2. [http.middlewares.test-stripprefixregex.stripPrefixRegex]
    3. regex = ["/foo/[a-z0-9]+/[0-9]+/"]

    File (YAML)

    Configuration Options

    The StripPrefixRegex middleware will:

    • strip the matching path prefix.
    • store the matching path prefix in a X-Forwarded-Prefix header.

    Tip

    Use a stripPrefixRegex middleware if your backend listens on the root path (/) but should be routeable on a specific prefix.

    Tip

    Regular expressions can be tested using online tools such as Go Playground or the .

    For instance, /products would match /products but also /products/shoes and /products/shirts.

    Since the path is stripped prior to forwarding, your backend is expected to listen on /.

    If your backend is serving assets (e.g., images or Javascript files), chances are it must return properly constructed relative URLs.

    The header can be queried to build such URLs dynamically.