In my K8S ingress config, I'm trying to redirect from (for example) old.mywebsite.com
to new.mywebsite.com
.
I can do this with the nginx.ingress.kubernetes.io/permanent-redirect
annotation, but unfortunately this causes a redirect directly to the target URL. For example, "old.mywebsite.com/some/path?with=parameters" will redirect to "new.mywebsite.com/". The path and query arguments are lost. Since this website has lots of incoming links to the old domain, redirecting with the path and query intact is absolutely crucial.
I can use a config snippet to do what I want:
nginx.ingress.kubernetes.io/server-snippet: |
if ($host ~ "old.mywebsite.com")
{
rewrite ^ https://new.mywebsite.com$request_uri? permanent;
}
This works, but it breaks automatic renewal of certificates for the old subdomain, since any HTTP requests to the old domain are rewritten to the new domain.
Is there any way I can achieve both? For example a different annotation that preserves the full request path or different snippet config that can make an exception for certbot?