How do I redirect a naked (apex) domain to www using Route 53?
RedirectAmazon Web-ServicesAmazon S3DnsAmazon Route53Redirect Problem Overview
I need to do a 301 redirect from example.com to www.example.com using Route 53 (and S3 if necessary). There are a few solutions for similar problems but they either do not address how to redirect from the apex or they simply don't work.
When I follow the steps here, Route 53 tells me I can't add a CNAME to the apex domain. Therefore, I'm stuck in the mud.
This seems dumb simple but Amazon is making it hard. Any help would be appreciated.
Redirect Solutions
Solution 1 - Redirect
I just managed to figure this out yesterday:
-
Go to your S3 console at https://console.aws.amazon.com/s3/home and click Create bucket. For Bucket name enter in your naked domain name, e.g. for www.example.com, you would put just example.com. Then click Create.
-
Click on the name of the new bucket, then click Properties > Static website hosting. On the menu that appears select Redirect requests. For Target bucket or domain enter in the full domain, such as www.example.com. For Protocol put in the desired protocol, http or https. Click Save.
-
Open your Route 53 hosted zone by navigating to https://console.aws.amazon.com/route53/home and clicking Hosted zones in the menu to the left. Select your domain and click on Create Record Set. Leave the Name area blank, and leave the default type at A - IPv4 address. Select Yes for Alias, and click on the Alias Target textbox. You may have to wait a few moments for the values in the dropdown menu that appears to populate. At this point the menu should contain the S3 Website Endpoint you created in steps 1 and 2. Select it.
Lastly, click Create, and enjoy your new routing set-up!
Solution 2 - Redirect
Try making an alias record instead of CNAME.
Per this answer: https://stackoverflow.com/questions/20215729/rrset-of-type-cname-with-dns-name-foo-com-is-not-permitted-at-apex-in-zone-bar
Solution 3 - Redirect
The necessary steps are as follows:
- Create a new Bucket and call it exactly as your naked domain name (eg: example.com).
- In the Bucket properties, select "Static Website Hosting" and make it redirect to your www.example.com domain. Click "save".
- Go to your Route53 hosted zone, and create an A record. Mark it as an Alias, and from the dropdown select your recently created bucket.
- You're ready.
Solution 4 - Redirect
If you are using an Application Load Balancer, they added support for redirects. You point your zone apex at your ELB (using an Alias) and have ELB do the redirect to www.example.com
This seems like a much better solution than setting up a bucket, adding static hosting, redirect, etc.
Solution 5 - Redirect
For those who need to redirect a naked domain example.com to www.example.com
The best practice is to create a new Load Balancer
with Listener on port 80 http
that redirect 301 to www.example.com
In case you have https
running just add another listener on port 443 that redirect 301 to www.example.com
Once you have finished with the listeners go to
Route 53 > your domain> Create Record
that points your new load balancer with the redirect listeners
record name: example.com
Record Type: A
Alias: Yes
Alias to Application and Load Balancer...
Select your location
Select your new Load Balancer
Save it and wait some minutes and now all request for naked example.com redirect 301 to www.example included for https request.
Note: If you want to redirect http request to https request you need to do the same procedure but instead of a redirect listener you need to set-up a forward listener to https.