<p>I have an application running in kubernetes that I can access outside the cluster from my browser on:</p>
<p><a href="http://myapp.internal/myapp/content" rel="nofollow noreferrer">http://myapp.internal/myapp/content</a></p>
<p>using the below Ingress:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/instance: myapp
    app.kubernetes.io/name: myapp
  name: myapp
  namespace: samples
spec:
  rules:
  - host: myapp.internal
    http:
      paths:
      - backend:
          serviceName: myapp
          servicePort: 8080
        path: /myapp/content
status:
  loadBalancer:
    ingress:
    - {}
</code></pre>
<p>Now I would like to access it on:</p>
<p><a href="http://myapp.internal/content" rel="nofollow noreferrer">http://myapp.internal/content</a></p>
<p>instead but without modifying my application (that's not an option at the moment).</p>
<p>Based on:</p>
<p><a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/</a></p>
<p>it seems I can just do:</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /myapp/content
</code></pre>
<p>So I have updated my ingress to look like this:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /myapp/content
  labels:
    app.kubernetes.io/instance: myapp
    app.kubernetes.io/name: myapp
  name: myapp
  namespace: samples
spec:
  rules:
  - host: myapp.internal
    http:
      paths:
      - backend:
          serviceName: myapp
          servicePort: 8080
        path: /content
status:
  loadBalancer:
    ingress:
    - {}
</code></pre>
<p>I would now assume that when I enter:</p>
<p><a href="http://myapp.internal/content" rel="nofollow noreferrer">http://myapp.internal/content</a></p>
<p>in my browser the above <code>rewrite-target</code> rule then translates that into:</p>
<p><a href="http://myapp.internal//myapp/content" rel="nofollow noreferrer">http://myapp.internal//myapp/content</a></p>
<p>which it actually does. But instead of seeing my content I just get:</p>
<pre><code>default backend - 404
</code></pre>
<p>Basically I need the reverse of this example:</p>
<p><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>So original example says:</p>
<pre><code>rewrite.bar.com/something/new rewrites to rewrite.bar.com/new
</code></pre>
<p>Where I need:</p>
<pre><code>rewrite.bar.com/new rewrites to rewrite.bar.com/something/new
</code></pre>
<p>What am I missing?</p>

u123
<p>Actually you do not need to set <code>nginx.ingress.kubernetes.io/rewrite-target: /myapp/content</code>. Understand the flow, by the path <code>/myapp/content</code> you are accessing <code>myapp</code> service so you should only just replace the path (as you want to redirect the path) <code>path: /content</code>, it will work fine. Now if you hit <code>/content</code> path then it will go to same service (named <code>myapp</code>) as like <code>/myapp/content</code> in previous.</p>
<p>The yaml should be like:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/instance: myapp
    app.kubernetes.io/name: myapp
  name: myapp
  namespace: samples
spec:
  rules:
  - host: myapp.internal
    http:
      paths:
      - backend:
          serviceName: myapp
          servicePort: 8080
        path: /content
status:
  loadBalancer:
    ingress:
</code></pre>
<h1>update</h1>
<p>actually your question is not clear, you want to hit <a href="http://myapp.internal/content" rel="nofollow noreferrer">http://myapp.internal/content</a> and redirect to <a href="http://myapp.internal/myapp/content" rel="nofollow noreferrer">http://myapp.internal/myapp/content</a>? If it is what you are looking then it's not possible by changing ingress, because your ingresd will match till <a href="http://myapp.internal" rel="nofollow noreferrer">http://myapp.internal</a> and rest of the part /content will go to your service backed pod, now if in your service backed pod you have myapp/content then how can you send content to get that?</p>
<p>One thing you can do is: run a pod where you need to run another application with <code>/content</code> path and it will just redirect to <code>myapp/content</code> pod, both pod can backed by the <code>myapp</code> service</p>
