<p>I am tying to put together a setup like this :</p>
<ul>
<li>example.com   <em>#frond end</em></li>
<li>example.com/api</li>
<li>example.com/authentication</li>
</ul>
<p>And obviously each of them separated applications and should be able to continue their own path , <code>ex.   http://example.com/api/v1/test?v=ok</code></p>
<p>Right now I have a yaml  like this:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
 name: test-ingress
 annotations:
   nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
 rules:
 - http:
     paths:
     - path: /
       backend:
         serviceName: frontend-service
         servicePort: 80
     - path: /api(/|$)(.*)
       backend:
         serviceName: backend-service
         servicePort: 80
     - path: /authentication(/|$)(.*)
       backend:
         serviceName: identityserver-service
         servicePort: 80
</code></pre>
<p>/api  and /authentication  behave the way I want, but the sub path for front end is not working.  So for example  <code> http://example.com/css/bootstrap.css</code> is not found.</p>
<p>So far I've tried to</p>
<p>1- add <code>(/|$)(.*)</code> at the and of front end path</p>
<p>2- add a copy of front end path with the same backed and  port  and path of <code>/.*</code></p>
<p>None of them solved the problem.</p>
<p>Here is the describe result:</p>
<pre><code>Name:             test-ingress
Namespace:        default
Address:          127.0.0.1
Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /                          frontend-service:80 (10.1.80.38:80,10.1.80.43:80,10.1.80.50:80)
              /api(/|$)(.*)              backend-service:80 (10.1.80.39:80,10.1.80.42:80,10.1.80.47:80)
              /authentication(/|$)(.*)   identityserver-service:80 (10.1.80.40:80,10.1.80.41:80,10.1.80.45:80)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /$2
Events:
  Type    Reason  Age                 From                      Message
  ----    ------  ----                ----                      -------
  Normal  UPDATE  43s (x14 over 13h)  nginx-ingress-controller  Ingress default/test-ingress
</code></pre>
<p>PS :   I'vd found a few answers that seems to be older than Version 0.22.0 and not working anymore ex .  <a href="https://stackoverflow.com/questions/49514702/kubernetes-ingress-with-multiple-target-rewrite">kubernetes ingress with multiple target-rewrite</a></p>

Daniel
<p>The problem in your case lies with incorrect regular expression.
The <code>$</code> operator matches the end of the string or end of a line if the multiline flag is enabled.  With first group you are capturing <code>/</code> or <code>$</code> but your string does not end and there is not match.</p>
<p>I tested this and it works with this regex:</p>
<pre><code> paths:
 - path: /()(.*)
   backend:
     serviceName: frontend-service
     servicePort: 80
</code></pre>
