<p>I have a simple ingress configuration file-</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /link2/link3/
  name: tut-ingress
  namespace: default
spec:
  rules:
    - host: tutorial.com
      http:
        paths:
          - path: /link1/
            pathType: Prefix
            backend:
              service:
                name: nginx-ingress-tut-service
                port:
                  number: 8080
</code></pre>
<p>in which requests coming to <code>/link1</code> or <code>/link1/</code> are rewritten to
<code>/link2/link3/</code>.
When I access it using <code>http://tutorial.com/link1/</code>
I am shown the correct result but when I access it using
<code>http://tutorial.com/link1</code>, I get a 404 not found.

The <code>nginx-ingress-tut-service</code> has the following endpoints-</p>
<ul>
<li><code>/</code></li>
<li><code>/link1</code></li>
<li><code>/link2/link3</code></li>
</ul>
<p>I am a beginner in the web domain, any help will be appreciated.</p>
<p>When I change it to-</p>
<pre class="lang-yaml prettyprint-override"><code>- path: /link1
</code></pre>
<p>it starts working fine, but can anybody tell why is it not working with <code>/link1/</code>.</p>
<p>Helpful resources -
<a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#examples" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/#examples</a></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>Edit- Please also explain what happens when you write a full HTTP link in
<code>nginx.ingress.kubernetes.io/rewrite-target</code></p>

BeastMaster64
<p>The answer is posted in the comment:</p>
<blockquote>
<p>Well, <code>/link1/</code> is not a prefix of <code>/link1</code> because a prefix must be the same length or longer than the target string</p>
</blockquote>
<p>If you have</p>
<pre class="lang-yaml prettyprint-override"><code>- path: /link1/
</code></pre>
<p>the string to match will have to have a <code>/</code> character at the end of the path. Everything works correctly. In this situation if you try to access by the link <code>http://tutorial.com/link1</code> you will get 404 error, because ingress was expecting  <code>http://tutorial.com/link1/</code>.</p>
<p>For more you can see <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/#examples" rel="nofollow noreferrer">examples of rewrite rule</a> and documentation about <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types" rel="nofollow noreferrer">path types</a>:</p>
<blockquote>
<p>Each path in an Ingress is required to have a corresponding path type. Paths that do not include an explicit  <code>pathType</code>  will fail validation. There are three supported path types:</p>
<ul>
<li><p><code>ImplementationSpecific</code>: With this path type, matching is up to the IngressClass. Implementations can treat this as a separate  <code>pathType</code>  or treat it identically to  <code>Prefix</code>  or  <code>Exact</code>  path types.</p>
</li>
<li><p><code>Exact</code>: Matches the URL path exactly and with case sensitivity.</p>
</li>
<li><p><strong><code>Prefix</code>: Matches based on a URL path prefix split by  <code>/</code>. Matching is case sensitive and done on a path element by element basis. A path element refers to the list of labels in the path split by the  <code>/</code>  separator. A request is a match for path  <em>p</em>  if every  <em>p</em>  is an element-wise prefix of  <em>p</em>  of the request path.</strong></p>
</li>
</ul>
</blockquote>
<p><strong>EDIT:</strong>
Based on documentation this should work, but it looks like there is a <a href="https://github.com/kubernetes/ingress-nginx/issues/8047" rel="nofollow noreferrer">fresh problem with nginx ingress</a>. The problem is still unresolved. You can use workaround posted in <a href="https://github.com/kubernetes/ingress-nginx/issues/646" rel="nofollow noreferrer">this topic</a> or try to change your you similar to this:</p>
<pre><code>- path: /link1(/|$)
</code></pre>
