<pre><code>{{- $root := . -}}
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ include &quot;ingress.name&quot; . }}
  namespace: demo
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    -   host: &quot;*.{{ .Values.host }}&quot;
        http:
          paths:
            {{- range $index, $service := .Values.deployments }}
            -   path: {{ $service.pathPrefix }}(/|$)(.*)
                backend:
                  serviceName: {{ $service.deploymentName }}
                  servicePort: 80
            {{- end  }}
---
</code></pre>
<p>This ingress configuration is successfully working.</p>
<p>Additionally it is required that when anyone hit URL: <a href="http://example.com" rel="nofollow noreferrer">http://example.com</a>, it should redirect <a href="http://example.com/login" rel="nofollow noreferrer">http://example.com/login</a> permanently, so how can i achieve it?</p>
<p>Thanks.</p>

Jatin Panchal
<p>You can add the annotation like</p>
<pre><code>nginx.ingress.kubernetes.io/server-snippet: |
      location ~ / {
         rewrite / https://&lt;example.com to use $host&gt;/login permanent;
      }
</code></pre>
<p>if want to use the configuration snippet</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
      if ($host = 'https://example.com/') {
        return 301 https://example.com/login;
      }
</code></pre>
<p>or</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
         rewrite / https://example.com/login permanent;
</code></pre>
<p>you can use the variables also if looking instead of using the fixed value.</p>
<p><code>$request_uri, $uri, $host</code> are few of variables you can leverage.</p>
