UPDATED: fixed missing/broken gist link with the code snippet.
UPDATE #2 May 24, 2017: updating this post since S3 has a new UI.
Recently I decided to ditch registrar DNS Managers like GoDaddy’s in favor of Amazon’s Route53. I really like their console and the DNS is snappy and responsive, not to mention the handy features when creating and pointing to Load Balancers for your TLD. However, one draw back of Route 53 is the lack of subdomain forwarding. Below is a quick solution.
All you will need is an Amazon S3 bucket, the static website end-point, and a Route 53 CNAME.
1.) Create an S3 Bucket: Name the bucket ie: subdomaintoForward.mydomain.com. It has to be the exact subdomain you wish to forward otherwise Route 53 won’t resolve. Choose the region and create!
2.) Set Properties: I don’t typically Set Properties for S3 bucket forwarding, but it’s an option for your specific use case. Skip this step if you’re not familiar with this.
3.) Set Permissions: Be sure to set the group permissions under Everyone to Read. This will allow the public to access the S3 bucket contents.
4.) Enable S3 Website Hosting: Open your new bucket and click the “Properties” tab.
Open up “Static Website Hosting” than select “Use this bucket to host a website”. Make the “Index document” simply index.html. After that, you will need to copy/paste the sample JSON below into “Redirection Rules”.
IMPORTANT: Open up Notepad or SimpleEdit and make note of the ENDPOINT. This will be used in Step 5 when you point the subdomain DNS.
Be sure to read the JSON closely and edit HostName and ReplaceKeyPrefixWith values. Paste in the XML below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Again, just for clarification lets breaks down the JSON above. In this example, I want subdomaintoForward.mydomain.com to 301 redirect to http://domaintoforwardto.com/anything/after/thedomain/index5.html – compare this URL to the XML above, you should be able to figure out the syntax.
5.) Create A CNAME in Route 53: Make note of the “Static Website Hosting” End-point, copy that, then open up Amazon Route 53. Select your Hosted Zone and click “Go to Record Sets”. Click “Create Record Set” and configure your Record. In this example, domaintoForward is the subdomain, use CNAME, and paste in the Static Web Hosting End-point into Value. Create the record.
8 thoughts on “301 Redirect Subdomain Forwarding On AWS Route 53”
Thanks for sharing!
Where do I get the feature/link to create an S3 Bucket?
Never mind, go it. 🙂
Thanks for sharing. Is there a way to have multiple rerouting rules? For instance say you want reroute:
but you want to also reroute:
good lord i could kiss you
I just rewrote a portion of this tutorial since S3 has a new UI. I’m sure it confused a few people discovering this. If you have questions feel free to drop a comment.
Can this work also for *.something.com -> *.somethingelse.com and keeping the subdomain
Yes you should be able to do this.