Search code examples
amazon-web-servicesamazon-s3amazon-route53aws-application-load-balancer

Amazon Route 53 to redirect multiple subdomains to other subdomains without S3


I have a domain called example.com which has around 20 subdomains, for instance subdomain_1.example.com, subdomain_2.example.com, etc.

I am changing my domain from example.com to newdomain.com. Furthermore, I did the set up of all subdomains on Route 53, now both domains are loading my website, I would like to redirect all the traffic from old subdomains to new subdomains. For instance, if a user requests for subdomain_15.example.com should be redirected to subdomain_15.newdomain.com.

I read the solution provided by AWS regarding a S3 bucket per route, but I have a lot of subdomains, and I am wondering if there is a more efficient way to create the redirect rule for all domain and subdomains at once.


Solution

  • You need compute for this, if you do not want to use S3's built-in HTTP server/endpoint with its redirect capability.

    There are quite a few options:

    1. map your old domain to an API in API Gateway and use a Lambda function to serve the redirect HTTP response
    2. map your old domain to a CloudFront distribution and use Lambda@Edge on "viewer request" to serve the redirect HTTP response
    3. map your old domain to an Application Load Balancer (costs per uptime, though!) and configure a redirect to your new domain (using the same path as variable) in the listener rules
    4. more options using "serverful" resources, such as using a simple EC2 instance as web server and configuring that to serve the HTTP redirect response, of course, but unnecessary

    You didn't tell, what system is actually serving your domain, so another option might also be to just configure your webserver (if any) to serve the HTTP redirect response from within your application (if any).