<p>I have one service and a single ingress resource with kubenetes nginx ingress controller. I want the <code>/student</code> path of my url to go to the root of the application and match any other url segments which follow the <code>student</code>. </p>

<p>For example: <a href="http://example.com/student/ver" rel="nofollow noreferrer">http://example.com/student/ver</a> should match the <code>/ver</code> route of my application. </p>

<p>However, my ingress always hit the application with the <code>/student</code> url path prefixing the other url segments. If I call <a href="http://example.com/student/ver" rel="nofollow noreferrer">http://example.com/student/ver</a>, my application is hit with the same url (<code>student/ver</code>).</p>

<p>My ingress:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  name: ingress-resource
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: lesson-streaming
          servicePort: 80
        path: /student
</code></pre>

<p>I spent days with this and was not successful once. </p>

<hr>

<p>Edit: </p>

<p>The ingress is changed to the following - not my requests say <code>http 404</code></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/rewrite-target: /$2
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  name: ingress-resource
  namespace: default
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: lesson-streaming
          servicePort: 80
        path: /student(/|$)(.*)
</code></pre>

Charlie
<p>You can follow the <a href="https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#examples" rel="noreferrer">link</a> to use the <code>rewrite-target</code> annotation correctly and keep the right key <code>nginx.ingress.kubernetes.io/rewrite-target</code>.</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)
</code></pre>
