<p>I'm having some issues when using a path to point to a different 
Kubernetes service. </p>

<p>I'm pointing to a secondary service using the path <strong>/secondary-app</strong> and I can see through my logs that I am correctly reaching that service. </p>

<p>My issue is that any included resource on the site, let's say <strong>/css/main.css</strong> for example, end up not found resulting in a 404.</p>

<p>Here's a slimmed down version of my ingress:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: my-app
spec:
  rules:
  - host: my-app.example.com
    http:
      paths:
      - backend:
        path: /
          serviceName: my-app
          servicePort: http
      - backend:
        path: /secondary-app        
          serviceName: secondary-app
          servicePort: http
</code></pre>

<p>I've tried a few things and haven't yet been able to make it work. Do I maybe need to do some apache rewrites?</p>

<p>Any help would be appreciated.</p>

<h2>Edit - Solution</h2>

<p>Thanks to some help from @mk_sta I was able to get my secondary service application working by using the <code>nginx.ingress.kubernetes.io/configuration-snippet</code> annotation like so:</p>

<pre><code>  nginx.ingress.kubernetes.io/configuration-snippet: |
      if ($request_uri = '/?%secondary-app') { rewrite /(.*) secondary-app/$1 break; }
</code></pre>

<p>It still needs a bit of tweaking for my specific app but that worked exactly how I needed it to.</p>

Beans
<p>I guess <code>nginx.ingress.kubernetes.io/rewrite-target: /</code> annotation in your <code>Ingress</code> configuration doesn't bring any success for multipath rewrite target paths, read more <a href="https://stackoverflow.com/questions/49514702/kubernetes-ingress-with-multiple-target-rewrite">here</a>. However, you can consider to use <a href="https://github.com/nginxinc/kubernetes-ingress" rel="nofollow noreferrer">Nginx Plus Ingress controller</a>, shipped with <code>nginx.org/rewrites:</code> annotation and can be used for pointing URI paths to multiple services as described in this <a href="https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/rewrites" rel="nofollow noreferrer">example</a>.</p>

<p>You can also think about using <code>nginx.ingress.kubernetes.io/configuration-snippet</code> <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md#configuration-snippet" rel="nofollow noreferrer">annotation</a> for the existing <code>Ingress</code>, which can adjust rewrite rules to Nginx location, something like:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite /first-app/(.*) $1 break;
      rewrite /secondary-app/(.*) /$1 break;
  name: my-app
spec:
  rules:
  - host: my-app.example.com
    http:
      paths:
      - backend:
        path: /first-app
          serviceName: my-app
          servicePort: http
      - backend:
        path: /secondary-app        
          serviceName: secondary-app
          servicePort: http
</code></pre>
