<p>I have a website deployed in Kubernetes and ingress controller working.</p>
<p>I need to redirect my old subdomain to the new subdomain(old.example.com -&gt; new.example.com).</p>
<p>I made some research and found that I have to use the annotation:</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target
</code></pre>
<p>my ingress file:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rancher-ing
  namespace: test
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/tls-acme: &quot;true&quot;
    ingress.kubernetes.io/secure-backends: &quot;true&quot;
    ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$1

spec:
  tls:
  - hosts:
    - new.example.com
    secretName: new.example.com
  rules:
  - host: new.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: rancher-logo-service
            port:
              number: 80
  - host: old.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: rancher-logo-service
            port:
              number: 80
</code></pre>

gharbi.bdr
<p>i created an ingress controller config for the new url.
and updated the old config into this:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rancher-ing-redirect
  namespace: test
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/tls-acme: &quot;true&quot;
    ingress.kubernetes.io/secure-backends: &quot;true&quot;
    ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: https://new.example.com/
spec:
  rules:
  - host: old.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: rancher-logo-service
            port:
              number: 80
</code></pre>
