title: Nginx Ingress Controller trailling slash with HTTPS redirect
body: <p>Nginx Ingress Controller trailling slash with HTTPS redirect</p>
  <p>I'm trying to redirect requests from HTTP to HTTPS using an Ingress with Nginx Ingress Controller. My app is written in Django v3.0.7, my Nginx Controller is v0.46.0 and k8s v1.19.8.</p>
  <p>I have the following ingress:</p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: INGRESS-NAME
    namespace: INGRESS-NS
    annotations:
      kubernetes.io/ingress.class: &quot;nginx&quot;
      nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
      nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
      nginx.ingress.kubernetes.io/rewrite-target: /api/v1/$1/
      cert-manager.io/cluster-issuer: &quot;ISSUER-NAME&quot;
      nginx.ingress.kubernetes.io/permanent-redirect-code: '308'
  spec:
    tls:
    ...
    rules:
    - host: MY-DOMAIN
      http:
        paths:
        - path: /api/v1/?(.*)
          pathType: Prefix
          backend:
            service:
              name: SVC-NAME
              port:
                number: SVC-PORT
  </code></pre>
  <p>Requests at <code>https://.../api/v1/get-token/</code>, raise this error:</p>
  <p><code>[05/May/2021:20:39:49 +0000] &quot;POST /api/v1/get-token// HTTP/1.1&quot; 404</code> =&gt; POST get an extra <code>/</code> at the end. But the same request with HTTP or <code>https://.../api/v1/get-token</code> (no trailing <code>/</code>) is fine.</p>
  <p>If I remove the</p>
  <pre><code>annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /api/v1/$1/
  </code></pre>
  <p>The redirect removes trailing <code>/</code> and it causes POST to turn into GET in all HTTP POST request causing an 403 - Method not allowed as shown in Nginx Logs:</p>
  <pre><code>[05/May/2021:20:54:52 +0000] &quot;POST /api/v1/get-token HTTP/1.1&quot; 308 164
  [05/May/2021:20:54:53 +0000] &quot;POST /api/v1/get-token HTTP/1.1&quot; 301 0 
  [05/May/2021:20:54:53 +0000] &quot;GET /api/v1/get-token/ HTTP/1.1&quot; 405
  </code></pre>
  <p>but HTTP POST request works fine with <code>http://.../api/v1/get-token//</code> (two trailing <code>/</code>).</p>
  <p>Is there a way to solve this problem? The 308 HTTP -&gt; HTTPS redirect is important, so I can't remove it, but is there a way to force requests to have one, and only one, trailing <code>/</code>? Thanks.</p>