<p>Based on <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">this guide</a>.</p>
<p>I have created this ingress:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/enable-rewrite-log: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: ing-something
  namespace: samples
spec:
  rules:
  - host: myhost.internal
    http:
      paths:
      - backend:
          serviceName: my-app
          servicePort: 8080
        path: /api(/|$)(.*)
  tls:
  - hosts:
    - myhost.internal
    secretName: lets
status:
  loadBalancer:
    ingress:
    - {}
</code></pre>
<p>When I take a look at the bottom of the generated nginx.config it contains:</p>
<pre><code>## start server myhost.internal
server {
    server_name myhost.internal ;
    
    listen 80;
    
    set $proxy_upstream_name &quot;-&quot;;
    set $pass_access_scheme $scheme;
    set $pass_server_port $server_port;
    set $best_http_host $http_host;
    set $pass_port $pass_server_port;
    
    listen 443  ssl http2;
    ...
    location ~* &quot;^/api(/|$)(.*)&quot; {
        
        set $namespace      &quot;samples&quot;;
        set $ingress_name   &quot;ing-something&quot;;
        set $service_name   &quot;my-app&quot;;
        set $service_port   &quot;8080&quot;;
    set $location_path  &quot;/api(/|${literal_dollar})(.*)&quot;;
        
        ...
        

        
        rewrite &quot;(?i)/api(/|$)(.*)&quot; /$2 break;
        proxy_pass http://upstream_balancer;
        
        proxy_redirect                          off;
        
    }
    
    location ~* &quot;^/&quot; {
        
        set $namespace      &quot;&quot;;
        set $ingress_name   &quot;&quot;;
        set $service_name   &quot;&quot;;
        ...
    }
</code></pre>
<p>I don't understand where this part <code>(?i)</code> is coming from in:</p>
<pre><code>        rewrite &quot;(?i)/api(/|$)(.*)&quot; /$2 break;
</code></pre>
<p>and what it means.</p>
<p>Any ideas?</p>

u123
<p>This is a community wiki answer based on the info from the comments and posted for better visibility. Feel free to expand it.</p>
<p>As already pointed out in the comments, the path matching <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#use-regex" rel="nofollow noreferrer">is case-insensitive by default</a>:</p>
<blockquote>
<p>Using the <code>nginx.ingress.kubernetes.io/use-regex</code> annotation will
indicate whether or not the paths defined on an Ingress use regular
expressions. The default value is <code>false</code>.</p>
<p>The following will indicate that regular expression paths are being
used:</p>
<pre><code>nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
</code></pre>
<p>The following will indicate that regular expression paths are not
being used:</p>
<pre><code>nginx.ingress.kubernetes.io/use-regex: &quot;false&quot;
</code></pre>
<p>When this annotation is set to <code>true</code>, the case insensitive regular
expression <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#location" rel="nofollow noreferrer">location modifier</a> will be enforced on ALL paths for a
given host regardless of what Ingress they are defined on.</p>
<p>Additionally, if the <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite" rel="nofollow noreferrer"><code>rewrite-target</code> annotation</a> is used on any
Ingress for a given host, then the case insensitive regular expression
<a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#location" rel="nofollow noreferrer">location modifier</a> will be enforced on ALL paths for a given host
regardless of what Ingress they are defined on.</p>
<p>Please read about <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/" rel="nofollow noreferrer">ingress path matching</a> before using this
modifier.</p>
</blockquote>
<p>And all the specifics regarding the Mode Modifiers can be found <a href="https://www.regular-expressions.info/refmodifiers.html" rel="nofollow noreferrer">here</a>:</p>
<blockquote>
<p>Mode modifier syntax consists of two elements that differ among regex
flavors. Parentheses and a question mark are used to add the modifier
to the regex. Depending on its position in the regex and the regex
flavor it may affect the whole regex or part of it. If a flavor
supports at least one modifier syntax, then it will also support one
or more letters that can be used inside the modifier to toggle
specific modes. If it doesn’t, “n/a” is indicated for all letters for
that flavors.</p>
</blockquote>
<p>Notice the <a href="https://www.regular-expressions.info/modifiers.html" rel="nofollow noreferrer">Specifying Modes Inside The Regular Expression</a> for case-insensitivity:</p>
<pre><code>(?i)    Turn on case insensitivity. (?i)a matches a and A.
</code></pre>
