Recently I needed to redirect an apex domain in Route 53 to another apex domain. I thought this would be a simple process of adding a CNAME, however this isn’t possible in Route 53.
Luckily, the solution is a simnple one. In this post, I’ll show you how to redirect an apex domain (i.e. example.com) to another apex domain (i.e. example.org) using an S3 Bucket.
What You’ll Need
Firstly, you’ll need a Route 53 hosted zone for the apex domain that you want to redirect from. You’ll also need an S3 Bucket that is named exactly the same as that apex domain. In our example, the S3 Bucket needs to be called
thetestlabs.com since that is the domain we’re redirecting from.
How to Redirect an Apex Domain in Route 53
In this example, we’re redirecting from
thetestlabs.io. You’ll obviously need to substitute those domains with your own.
Firstly, head over to the S3 console and select the S3 Bucket with the same name as the apex domain that you want to redirect. Obviously if you don’t have one, you’ll need to create one at this stage.
Properties and scroll down to
Static website hosting at the very bottom. Select the
Edit button and use the following values:
Static website hosting : Enable
Hosting type : Redirect requests for an object
Host name : thetestlabs.io (this is the domain that you want to redirect to)
Protocol : https
To complete the setup, head over to Route 53 and the hosted zone that you wish to redirect from, in our case
thetestlabs.com. Go ahead and create a new record with the following values:
Record name : Leave blank, since we’re redirecting the apex domain and not a subdomain
Record type : Leave as the default, which should be
A - Routes trsffic to an IPv4 address and some AWS resources
Alias : Switch this to yes
Route traffic to :
- Alias to S3 website endpoint
- AWS Region where your S3 Bucket is registered
Routing policy : Simple routing
Evaluate target health : Switch this to no
As you can see from the screenshot below, as long as the S3 Bucket is named correctly and you’ve chosen the correct Region, the dropdown will show the name of the bucket in brackets:
This is a very simple, if not intuitive, method of redirecting apex domains in Route 53 to another domain.
You can also use this method to redirect subdomains if you wanted to, for example redirecting