<p>I am struggling with making a rewrite/redirect rule on nginx-ingress on Kubernetes.</p>
<p>According to the doc <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/</a> it says it is possible with the annotation &quot;<code>nginx.ingress.kubernetes.io/rewrite-target</code>&quot;, but unable to implement on my ingress. Maybe I am doing it wrong.</p>
<p>An example, portion of nginx-ingress yaml file.</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    example.com/deployment-name: frontend-page
    example.com/ingress-hostnames: www.example.com
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: www.example.com
    http:
      paths:
      - backend:
          serviceName: frontend-page
          servicePort: 8080
        path: /front(/|$)(.*)
</code></pre>
<p>Tried another way around as well but no luck:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    example.com/deployment-name: frontend-page
    example.com/ingress-hostnames: www.example.com
    nginx.ingress.kubernetes.io/rewrite-target: /shop
spec:
  rules:
  - host: www.example.com
    http:
      paths:
      - backend:
          serviceName: frontend-page
          servicePort: 8080
        path: /
</code></pre>
<p>I want to redirect any traffic to the page <code>www.example.com/front/checkdomain</code> to <code>www.example.com/checkdomain</code>. I want to remove that &quot;front&quot; path comes in between.</p>

vjwilson
<p>try this with an updated API version, hope your ingress supports <code>networking.k8s.io/v1beta1</code></p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    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>
<p>Example : <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/#examples" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/#examples</a></p>
