<p>I deployed 2 front-end applications that are based on angular. I use ingress-nginx (<code>k8s.gcr.io/ingress-nginx/controller:v0.44.0</code>) with the following configurations to route the requests to these applications:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: portal-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths:
      - path: /?(.*)
        backend:
          serviceName: app1
          servicePort: 80
      - path: /app2
        backend:
          serviceName: app2
          servicePort: 80
</code></pre>
<p>When I hit the <code>&lt;ip-address&gt;/</code> it is routing to app1, but when I hit <code>&lt;ip-address&gt;/app2</code> it is routing back to app1.</p>

<p>According to the <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/#path-priority" rel="noreferrer">ingress-nginx documentation</a>, the first step it follows is to order the paths in descending length, then it transforms these paths into nginx <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#location" rel="noreferrer">location blocks</a>. nginx follows a first-match policy on these blocks.</p>
<p>In your case, you can provide both paths, and as <code>/app2</code> is longer than <code>/</code>, it will be written first in the nginx configuration. Meaning <code>/app2</code> will have a chance to be matched first (and send the traffic to <em>app2</em>), while everything else will go to <em>app1</em>. You don't need regexes to achieve this.</p>
<p>Code:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: portal-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: app1
          servicePort: 80
      - path: /app2
        backend:
          serviceName: app2
          servicePort: 80
</code></pre>
