Redirect Apex or Root Domain to www with AWS S3 and Route53

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to redirect a root domain (apex) to a host like www. Such as, example.com redirecting to www.example.com.

In this walkthrough it is referring to the newer S3 web Console. It can be done about the same in the legacy console, but selections may not match exactly.


Prerequisites

  • Domain DNS hosted in Route 53


Create S3 Bucket

  1. Create an S3 Bucket named as the root domain
    1. example.com
  2. Select the Bucket name to open it up in console
  3. Select Properties | Static Website Hosting
  4. Select Redirect Requests
  5. Enter host name
    1. www.example.com
  6. Select Save
S3 Enable static web hosting


Configure Route 53

  1. Browse to Route 53 Console
  2. Select Hosted Zones
  3. Select the appropriate DNS Zone
    1. example.com
  4. Delete any example.com CNAME, Aliases or A records that may exist
  5. Select Create Record Set
  6. Leave Name Blank
  7. Leave Record Type as default
  8. Select Alias = Yes
  9. Select Alias Target drop-down
  10. Select the S3 Website Endpoint we just created.
  11. Leave Record Policy as Simple
  12. Select Create
Aws-route53-create-alias-record


Test

curl -I example.com
HTTP/1.1 301 Moved Permanently
x-amz-id-2: lkajdflijfieinfnvkijdskfjlsidjfiowienkcnksihjerlujljlsjdslfjlinvnnahsudgfuhijhfnj
x-amz-request-id: 1234567ABC
Date: Thu, 26 Jan 2017 20:11:13 GMT
Location: http://www.example.com/
Content-Length: 0
Server: AmazonS3

Sources