<p>I did exactly as is it told here: <a href="https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#examples" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#examples</a></p>

<pre><code>$ echo '
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: coffee-svc
          servicePort: 80
        path: /something(/|$)(.*)
' | kubectl create -f -
</code></pre>

<p>The ingress is created, I added <code>rewrite.bar.com</code> to my <code>/etc/hosts</code> to the ip of the minikube.
<code>coffee-svs</code> is the service from this example: <a href="https://github.com/nginxinc/NGINX-Demos/tree/master/kubernetes-demo-nginx-ingress-resources" rel="nofollow noreferrer">https://github.com/nginxinc/NGINX-Demos/tree/master/kubernetes-demo-nginx-ingress-resources</a></p>

<p>Yet there is no rewrite happening, I have exactly the same use case as shown here: <a href="https://stackoverflow.com/questions/61185530/another-nginx-ingress-rewrite-target-problem">Another nginx ingress rewrite-target problem</a>, yet the proposed solution does not work.</p>

<p>When I do <code>curl rewrite.bar.com/something</code> there is a <code>404 Not Found</code> response.</p>

<p>The expected behavior would be that <code>rewrite.bar.com/something</code> is rewritten as <code>rewrite.bar.com/</code> and then call coffee-svc on path <code>/</code>.</p>

<p>Also doing <code>curl -I -k rewrite.bar.com/</code> returns:</p>

<pre><code>HTTP/1.1 404 Not Found
Server: nginx/1.17.9
Date: Sat, 02 May 2020 15:24:02 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive
</code></pre>

<p>I have nginx ingress installed with helm, using <code>stable/nginx-ingress</code>, currently version <code>0.30.0</code>.</p>

<p>Kubernetes version is <code>1.14</code>.</p>

<p>Edit:
Adding ingress-controller-pod logs</p>

<pre><code>I0502 15:52:00.344425       7 flags.go:215] Watching for Ingress class: nginx
W0502 15:52:00.344820       7 flags.go:260] SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)
W0502 15:52:00.344909       7 client_config.go:543] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0502 15:52:00.345341       7 main.go:193] Creating API client for https://10.96.0.1:443
I0502 15:52:00.355089       7 main.go:237] Running in Kubernetes cluster version v1.14 (v1.14.1) - git (clean) commit b7394102d6ef778017f2ca4046abbaa23b88c290 - platform linux/amd64
I0502 15:52:00.358184       7 main.go:91] Validated default/my-nginx-ingress-default-backend as the default backend.
I0502 15:52:00.836581       7 main.go:102] SSL fake certificate created /etc/ingress-controller/ssl/default-fake-certificate.pem
W0502 15:52:00.873934       7 store.go:628] Unexpected error reading configuration configmap: configmaps "my-nginx-ingress-controller" not found
I0502 15:52:00.911054       7 nginx.go:263] Starting NGINX Ingress controller
I0502 15:52:02.035037       7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"60b7853f-8c86-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367651", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/rewrite
I0502 15:52:02.113846       7 nginx.go:307] Starting NGINX process
I0502 15:52:02.116614       7 leaderelection.go:242] attempting to acquire leader lease  default/ingress-controller-leader-nginx...
I0502 15:52:02.123127       7 controller.go:137] Configuration changes detected, backend reload required.
I0502 15:52:02.135944       7 status.go:86] new leader elected: my-nginx-ingress-controller-6fcc8d7f97-r9d8t
I0502 15:52:02.321762       7 controller.go:153] Backend successfully reloaded.
I0502 15:52:02.321833       7 controller.go:162] Initial sync, sleeping for 1 second.
I0502 15:52:55.451512       7 leaderelection.go:252] successfully acquired lease default/ingress-controller-leader-nginx
I0502 15:52:55.452458       7 status.go:86] new leader elected: my-nginx-ingress-controller-6fcc8d7f97-7p8g6
I0502 15:52:55.470245       7 status.go:274] updating Ingress default/rewrite status from [] to [{10.0.2.15 }]
I0502 15:52:55.475571       7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"60b7853f-8c86-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367750", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress default/rewrite
I0502 15:53:18.288519       7 controller.go:137] Configuration changes detected, backend reload required.
I0502 15:53:18.291422       7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"60b7853f-8c86-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367783", FieldPath:""}): type: 'Normal' reason: 'DELETE' Ingress default/rewrite
I0502 15:53:18.403753       7 controller.go:153] Backend successfully reloaded.
I0502 15:53:20.187998       7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"0ba43588-8c8d-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367788", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/rewrite
I0502 15:53:21.623215       7 controller.go:137] Configuration changes detected, backend reload required.
I0502 15:53:21.796798       7 controller.go:153] Backend successfully reloaded.
</code></pre>

FCR
<p>Finnally I solved it by removing the entire minikube cluster:</p>

<pre><code>minikube delete
minikube start
</code></pre>

<p>There was somewhere, somehow a configuration affecting the ingress. Then it worked fine. Pitty I couldn't know the culprit config or deployment.</p>
