<p>I'm running through what looks like a configuration issue! I am using traefik as ingress controller within kubernetes and I have an ingress to route some URLs to route some frontends to various backends. Let's say I have something like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: ReplacePathRegex
spec:
  rules:
  - host: foo.io
    http:
      paths:
      - path: /api/authservice/(.*) /$1
        backend:
          serviceName: auth
          servicePort: 8901
      - path: /api/svcXXX/v1/files/cover/(.*) /v1/files/cover/$1
        backend:
          serviceName: files
          servicePort: 8183
      - path: /api/svcXXX/v1/files/image/(.*) /v1/files/image/$1
        backend:
          serviceName: files
          servicePort: 8183
</code></pre>

<p>Using Postman (or any other client), if I POST a request on <code>http://foo.io/api/authservice/auth/oauth/token</code>, while looking in the access logs, it seems that it is routed to <code>http://foo.io/api/svcXXX/v1/files/image/(.*) /v1/files/image/$1</code>. I'm seeing this in the access logs:</p>

<p><code>[03/Jul/2018:12:57:17 +0000] "POST /api/authservice/auth/oauth/token HTTP/1.1" 401 102 "-" "PostmanRuntime/7.1.5" 15 "foo.io/api/svcXXX/v1/files/image/(.*) /v1/files/image/$1" 37ms</code></p>

<p>Am I doing something wrong ?</p>

Cedric Morent
<p><strong>Note:</strong> since the documentation is changed, I've updated the links, but content on the documentation pages would be different.</p>
<p><code>ReplacePathRegex</code> is a  <strong>modifier</strong> rule. According to <a href="https://doc.traefik.io/traefik/v1.7/basics/#modifiers" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p>Modifier rules only modify the request. They do not have any impact on routing decisions being made.</p>
<p>Following is the list of existing modifier rules:</p>
<ul>
<li><code>AddPrefix</code>: <code>/products</code>: Add path prefix to the existing request path prior to forwarding the request to the backend.</li>
<li><code>ReplacePath</code>: <code>/serverless-path</code>: Replaces the path and adds the old path to the X-Replaced-Path header. Useful for mapping to AWS Lambda or Google Cloud Functions.</li>
<li><code>ReplacePathRegex</code>: <code>^/api/v2/(.*) /api/$1</code>: 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.</li>
</ul>
</blockquote>
<p>To route requests, you should use <a href="https://doc.traefik.io/traefik/v1.7/basics/#matchers" rel="nofollow noreferrer"><strong>matchers</strong></a>:</p>
<blockquote>
<p>Matcher rules determine if a particular request should be forwarded to a backend.</p>
<p>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.</p>
<p>Separate multiple rule values by ; (semicolon) in order to enable ALL semantics (i.e., forward a request if all rules match).</p>
<p>###Path Matcher Usage Guidelines
This section explains when to use the various path matchers.</p>
<p>Use <code>Path</code> if your backend listens on the exact path only. For instance,
<code>Path: /products</code> would match <code>/products</code> but not <code>/products/shoes</code>.</p>
<p>Use a <code>*Prefix*</code> matcher if your backend listens on a particular base
path but also serves requests on sub-paths. For instance, <code>PathPrefix: /products</code> would match <code>/products</code> but also <code>/products/shoes</code> and
<code>/products/shirts</code>. Since the path is forwarded as-is, your backend is
expected to listen on /products.</p>
<p>Use a <code>*Strip</code> matcher if your backend listens on the root path (/) but
should be routable on a specific prefix. For instance,
<code>PathPrefixStrip: /products</code> would match <code>/products</code> but also
/<code>products/shoes</code> and <code>/products/shirts</code>. Since the path is stripped prior
to forwarding, your backend is expected to listen on <code>/</code>. If your
backend is serving assets (e.g., images or Javascript files), chances
are it must return properly constructed relative URLs. Continuing on
the example, the backend should return <code>/products/shoes/image.png</code> (and
not <code>/images.png</code> which Traefik would likely not be able to associate
with the same backend). The <code>X-Forwarded-Prefix</code> header (available since
Traefik 1.3) can be queried to build such URLs dynamically.</p>
<p>Instead of distinguishing your backends by path only, you can add a
Host matcher to the mix. That way, namespacing of your backends
happens on the basis of hosts in addition to paths.</p>
</blockquote>
<p>Full list of matchers and their descriptions can be found <a href="https://doc.traefik.io/traefik/middlewares/overview/" rel="nofollow noreferrer">here</a></p>
