amazon-web-serviceshttp-redirectdnsamazon-route53

How to add top level redirect on AWS Route 53?


I need to change domain name on aws Route 53, however I have multiple sub-domains as well. For example foo.com is my top level domain, however I also have app.foo.com and admin.foo.com.

I would like to set a single redirect for foo.com, for example to bar.com, and automatically change all sub-domains to redirect traffic to [subdomain].bar.com. So admin.foo.com would redirect to admin.bar.com. Is it possible to setup a single top level redirect that also affects all sub-domains?


Solution

  • Redirecting a domain like foo.com and all its subdomains (app.foo.com, admin.foo.com, etc.) to a new domain (bar.com) while preserving the subdomain structure can’t be done directly in Route 53 as far as I know.

    But you can use CloudFront and Lambda@edge to use it as a middleware and do this redirection for you.

    You just need to change domain names as CNAME pointing to the cloudfront and create the Lambda as a flexible and scalable way to handle dynamic redirection for all subdomains.