title: How to create a url redirect from a domain to another using nginx ingress controller and masking the url?
body: <p>I have the following problem to solve:</p>
  <p>I need to allow clients to use theirs custom domains for our website. I already created a whitelabel subdomain and ask to a client to create a CNAME record on their DNS pointing to it. What i'm trying to accomplish here is that when the client access the CNAME address, my nginx ingress controller recognize the address, redirect to the white label subdomain, keeping the original url using my certificate configured on the ingress.</p>
  <p>I have this ingress configured:</p>
  <pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    annotations:
      ingress.kubernetes.io/proxy-body-size: 50m
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/proxy-body-size: 50m
      nginx.ingress.kubernetes.io/rewrite-target: /$1
      nginx.ingress.kubernetes.io/server-snippet: |
        if ($http_host = clientsubdomain.clientdomain.com)
        {
           rewrite (.*) https://mywhitelabelsubdomain.domain.com$1;
        }
    name: ingress-resource
    namespace: mynamespace
    
  spec:
    rules:
    - host: mywhitelabelsubdomain.domain.com
      http:
        paths:
        - backend:
            serviceName: my-service
            servicePort: 80
          path: /?(.*)
    - host: clientsubdomain.clientdomain.com
      http:
        paths:
        - backend:
            serviceName: my-service
            servicePort: 80
          path: /?(.*)
    tls:
    - hosts:
      - mywhitelabelsubdomain.domain.com
      secretName: my-secret
  </code></pre>
  <p>But when I hit <a href="https://clientsubdomain.clientdomain.com" rel="nofollow noreferrer">https://clientsubdomain.clientdomain.com</a> it redirects to my <a href="https://mywhitelabelsubdomain.domain.com" rel="nofollow noreferrer">https://mywhitelabelsubdomain.domain.com</a> changing the url on the browser. How can I make this redirect keeping the original url?</p>
  <p>Thanks for the help!</p>