Path based routing issues Traefik as Ingress Controller Path based routing issues Traefik as Ingress Controller kubernetes kubernetes

Path based routing issues Traefik as Ingress Controller


Note: since the documentation is changed, I've updated the links, but content on the documentation pages would be different.

ReplacePathRegex is a modifier rule. According to documentation:

Modifier rules only modify the request. They do not have any impact on routing decisions being made.

Following is the list of existing modifier rules:

  • AddPrefix: /products: Add path prefix to the existing request path prior to forwarding the request to the backend.
  • ReplacePath: /serverless-path: Replaces the path and adds the old path to the X-Replaced-Path header. Useful for mapping to AWS Lambda or Google Cloud Functions.
  • ReplacePathRegex: ^/api/v2/(.*) /api/$1: Replaces the path with a regular expression and adds the old path to the X-Replaced-Path header. Separate the regular expression and the replacement by a space.

To route requests, you should use matchers:

Matcher rules determine if a particular request should be forwarded to a backend.

Separate multiple rule values by , (comma) in order to enable ANY semantics (i.e., forward a request if any rule matches). Does not work for Headers and HeadersRegexp.

Separate multiple rule values by ; (semicolon) in order to enable ALL semantics (i.e., forward a request if all rules match).

###Path Matcher Usage GuidelinesThis section explains when to use the various path matchers.

Use Path if your backend listens on the exact path only. For instance,Path: /products would match /products but not /products/shoes.

Use a *Prefix* matcher if your backend listens on a particular basepath but also serves requests on sub-paths. For instance, PathPrefix: /products would match /products but also /products/shoes and/products/shirts. Since the path is forwarded as-is, your backend isexpected to listen on /products.

Use a *Strip matcher if your backend listens on the root path (/) butshould be routable on a specific prefix. For instance,PathPrefixStrip: /products would match /products but also/products/shoes and /products/shirts. Since the path is stripped priorto forwarding, your backend is expected to listen on /. If yourbackend is serving assets (e.g., images or Javascript files), chancesare it must return properly constructed relative URLs. Continuing onthe example, the backend should return /products/shoes/image.png (andnot /images.png which Traefik would likely not be able to associatewith the same backend). The X-Forwarded-Prefix header (available sinceTraefik 1.3) can be queried to build such URLs dynamically.

Instead of distinguishing your backends by path only, you can add aHost matcher to the mix. That way, namespacing of your backendshappens on the basis of hosts in addition to paths.

Full list of matchers and their descriptions can be found here