Is there a way to redirect an apex domain to another domain using Amazon S3 and Amazon Route 53?

Last updated: 2022-09-30

I want to redirect internet traffic from my root (apex) domain (for instance, example.com) to another domain (for instance, example.net). How can I do this?

Resolution

Prerequisites

  • You have a hosted zone for the domain example.com that is hosted in Amazon Route 53.
  • You have permissions to add resource records to the hosted zone of example.com.
  • You have permissions to create an Amazon Simple Storage Service (Amazon S3) bucket.
  • You can create an S3 bucket with the exact name for example.com.
    Note: The sites must use HTTP because the redirect can't connect to Amazon S3 over HTTPS.

Use the following procedure to redirect your domain. In these steps, you redirect example.com to example.net.

  1. In the Amazon S3 console, create an S3 bucket with the exact name as example.com.
    Note: S3 bucket names must be globally unique. If the bucket name that you need is already in use, then you can't use Amazon S3 for redirection. Consider other workarounds, such as configuring redirection on your backend server.
  2. Select the bucket that you created, and then choose Properties. Expand the Static Website Hosting dropdown list, and then choose Redirect requests for an object.
  3. In the Host name field, enter example.net, and then choose Save.
  4. In the Route 53 console, select the hosted zone named example.com.
  5. Create a resource record for example.com with the following values:
    Record name: example.com
    Record Type: Choose A – IPv4 address.
    Route traffic to: Choose Alias to S3 website endpoint.
  6. Choose Region, and then enter the S3 endpoint that you created.
    Routing policy: Choose Simple.
    Evaluate Health Target: Choose No, and then choose Create Records.

Now, you can redirect example.com to example.net. To confirm, browse to example.com or curl to example.com. Confirm that you receive a “301 Moved Permanently” error in your curl output, and that the page redirects to example.net.