title: What exactly does nginx.ingress.kubernetes.io/rewrite-target: /$1 mean in minikube annotation?
body: <p>While working with minikube ingress, I have to write <code>nginx.ingress.kubernetes.io/rewrite-target: /$1</code>. I have been trying hard to understand why we need this annotation and how to use it.</p>
  <p>I know that the <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite" rel="noreferrer">doc</a> says the following:</p>
  <blockquote>
  <p>In some scenarios the exposed URL in the backend service differs from the specified path in the Ingress rule. Without a rewrite any request will return 404. Set the annotation nginx.ingress.kubernetes.io/rewrite-target to the path expected by the service.</p>
  </blockquote>
  <p>But I am not able to get the exact point of what exactly <code>the exposed URL in the backend service differs from the specified path in the Ingress rule</code> means. I am not able to get the idea clearly.</p>
  <p>Further, upon trying to execute ingress file with services:</p>
  <p>code 1:</p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: example-ingress
    namespace: example-namespace
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /$1
  spec:
    rules:
      - host: myexample.com
        http:
          paths:
            - path: /
              pathType: Prefix 
              backend:
                service:
                  name: example-service
                  port:
                    number: 80
  </code></pre>
  <p>code 2:</p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: example-ingress
    namespace: example-namespace
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /
  spec:
    rules:
      - host: myexample.com
        http:
          paths:
            - path: /
              pathType: Prefix 
              backend:
                service:
                  name: example-service
                  port:
                    number: 80
  </code></pre>
  <p>code 3:</p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: example-ingress
    namespace: example-namespace
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /$1
  spec:
    rules:
      - host: myexample.com
        http:
          paths:
            - path: /index
              pathType: Prefix 
              backend:
                service:
                  name: example-service
                  port:
                    number: 80
  </code></pre>
  <p>what exactly is the difference between each pair of the above 3 code snippets with respect to rewrite-target and path mentioned above?</p>
  <p>PS: I'm new to minikube and trying to figure out the exact way things work. Please help.</p>