<p>I had a working example of a project a year back, which is not working anymore.</p>

<p>It's basically related to change in the behavior of <code>nginx.ingress.kubernetes.io/rewrite-target</code> property mentioned here - <a href="https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite</a> </p>

<p>I have 3 application and I want to route based on conditions.</p>

<ul>
<li><code>/*</code> to frontend-cluster-ip-service</li>
<li><code>/api/battleship/*</code> to battleship-cluster-ip-service</li>
<li><code>/api/connect4/*</code> to connect-four-cluster-ip-service</li>
</ul>

<p>The working example that was working an year back was </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: frontend-cluster-ip-service
              servicePort: 3000
          - path: /api/connect4/
            backend:
              serviceName: connect-four-cluster-ip-service
              servicePort: 8080
          - path: /api/battleship/
            backend:
              serviceName: battleship-cluster-ip-service
              servicePort: 8080
</code></pre>

<p>However, this is not working anymore and only routing to <code>/</code> , i.e to frontend-cluster-ip-service is working. Routing to other serives fails and I get 404.</p>

<p>Then I came to know about the change in <code>nginx.ingress.kubernetes.io/rewrite-target</code>.</p>

<p>I tried following then</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: frontend-cluster-ip-service
              servicePort: 3000
          - path: /api/connect4(/|$)(.*)
            backend:
              serviceName: connect-four-cluster-ip-service
              servicePort: 8080
          - path: /api/battleship(/|$)(.*)
            backend:
              serviceName: battleship-cluster-ip-service
              servicePort: 8080

</code></pre>

<p>Now the routing to <code>connect-four-cluster-ip-service</code> and <code>battleship-cluster-ip-service</code> is working but <code>frontend-cluster-ip-service</code> is not working and few js files loads are showing error:</p>

<p><a href="https://i.stack.imgur.com/mBR23.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mBR23.png" alt="enter image description here"></a></p>

Dhananjay
<p>I had the same issue with a bit more complicated rewrite (it was only for one different path).</p>

<p>Making multiple Ingresses for each path worked for me but might not be the cleanest solution.</p>

<p>My ingress definition:
<a href="https://github.com/FORTH-ICS-INSPIRE/artemis/blob/master/artemis-chart/templates/ingresses.yaml" rel="nofollow noreferrer">https://github.com/FORTH-ICS-INSPIRE/artemis/blob/master/artemis-chart/templates/ingresses.yaml</a></p>
