<p>I am using the Nginx annotations in Helm like so:</p>
<pre><code>ingress:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  hosts:
    - host: &quot;example.com&quot;
      paths:
        - path: /api(/?)(.*)
</code></pre>
<p>When visiting <code>example.com/api/</code>, my URL is rewritten as expected and I am forwarded to my application.</p>
<p>However, when the trailing slash is omitted, e.g <code>example.com/api</code>, this no longer is the case. What could I do to ensure that the scenario without a trailing slash included is correctly evaluated?</p>

<p>I think you are searching for regex alternatives?</p>
<pre><code>ingress:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  hosts:
    - host: &quot;example.com&quot;
      paths:
        - path: /api(/|$)(.*)
</code></pre>
<p>Either after <code>/api</code> there's another <code>/</code> with whatever (captured by the <code>$2</code>) or there is the end of the line, which will make <code>/api</code> be rewritten to <code>/</code>.</p>
