<p>We want to load <strong>example.xyz.com</strong> in <strong>site.abc.com</strong>. The best way is to redirect/rewrite all the requests from <strong>site.abc.com</strong> to <strong>example.xyz.com</strong>. However, we don't want the browser URL to be changed. <a href="https://serverfault.com/questions/927820/nginx-rewrite-url-without-changing-browser-address">From this similar SO problem</a> we understand that we need an Nginx location config as below</p>
<pre><code>server {
    servername site.abc.com;
    listen        80;
    ....
    ....
    ....
    ....
    location / {                  
        proxy_pass  http://example.xyz.com;
        rewrite /(.*)$ /$1 break;
    }
}
</code></pre>
<p>However, I'm not sure how to create a similar rule in <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">Kubernetes ingress-nginx</a> as it adds proxy_pass for each rule, which prevents us from adding proxy_pass config in <code>nginx.ingress.kubernetes.io/configuration-snippet:</code> annotation.</p>
<p>Also providing <code>nginx.ingress.kubernetes.io/rewrite-target: http://example.xyz.com/$1</code> annotation in ingress as below, redirects to <strong>example.xyz.com</strong> instead of loading <strong>example.xyz.com</strong> in <strong>site.abc.com</strong>.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: http://example.xyz.com/$1
  name: url-rewrite
  namespace: default
spec:
  rules:
  - host: site.abc.com
    http:
      paths:
      - backend:
          service:
            name: service
            port:
              number: 80
        path: /(.*)
        pathType: ImplementationSpecific
</code></pre>
<p>How can we load <strong>example.xyz.com</strong> in <strong>site.abc.com</strong> without any change in browser URL using ingress-nginx in this case?</p>

Mani
<p>With <a href="https://stackoverflow.com/a/60354450/6663095">this solution</a> as a reference, pointed out by <a href="https://stackoverflow.com/users/11560878/wytrzyma%C5%82y-wiktor">@WytrzymałyWiktor</a> I was able to make changes and it worked.
Here is the updated ingress file.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
      location ~ &quot;^/(.*)&quot; {
        proxy_pass http://example.xyz.com;
        rewrite /(.*)$ /$1 break;
      }
  name: url-rewrite
  namespace: default
spec:
  rules:
  - host: site.abc.com
</code></pre>
<p>One problem though here in making SSL redirect work. In some cases the target(<strong><a href="http://example.xyz.com" rel="nofollow noreferrer">http://example.xyz.com</a></strong>) will return <code>302 /some/other/path</code> in such cases <a href="http://site.abc.com" rel="nofollow noreferrer">http://site.abc.com</a> gets redirected as <a href="http://site.abc.com/some/other/path" rel="nofollow noreferrer">http://site.abc.com/some/other/path</a>. Not sure how to make it to redirect as <a href="https://site.abc.com/some/other/path" rel="nofollow noreferrer">https://site.abc.com/some/other/path</a>.
Setting <code>nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;</code> and <code>nginx.ingress.kubernetes.io/force-ssl-redirect: &quot;true&quot;</code> doesn't seem to work.</p>
<p>Adding this as an answer for documentation, As it will be helpful for people with a similar problem. Not a possible duplicate as the referenced solution addresses on adding <code>proxy_pass</code> whereas this, addresses URL rewrite without changing browser URL.</p>
