I want to use Amazon Simple Storage Service (Amazon S3) and Amazon Route 53 to redirect traffic from my apex domain to its subdomain or to another domain.
Resolution
Prerequisites:
- Confirm that you have a hosted zone for your apex domain in Route 53.
- Verify that you have permissions to create records in the hosted zone for the apex domain and to create Amazon S3 buckets.
- Make sure that an Amazon S3 bucket with the same name as your apex domain doesn't already exist.
Create an S3 bucket to redirect your domain
Note: Amazon S3 website endpoints don't support HTTPS. To redirect both HTTP and HTTPS requests, use other methods such as an Application Load Balancer or Amazon CloudFront with an edge function. For more information, see How do I redirect a domain in CloudFront? and How can I use an Application Load Balancer to redirect one domain to another?
Complete the following steps:
- In the Amazon S3 console, create an Amazon S3 bucket with the exact name of your apex domain.
- Select the bucket that you created, and then choose Properties.
- Under Static website hosting, choose Edit.
- Choose Redirect requests for an object.
- For Host name, enter the website that you want to redirect to.
- For Protocol, choose HTTP or HTTPS for the redirected requests.
Note: If you don't specify a protocol, then the default option is none.
- Choose Save changes.
Create an Alias record to point to the S3 bucket
Complete the following steps:
- In the Route 53 console, select the hosted zone for your apex domain.
- Create an A-Alias record for the apex domain in the selected hosted zone with the following values:
For Record name, leave this field blank.
For Record Type, choose A – IPv4 address.
For Route traffic to, choose Alias to Amazon S3 website endpoint.
For Region, choose the AWS Region where your Amazon S3 bucket is located.
For Enter Amazon S3 Endpoint, from the dropdown list, select the Amazon S3 bucket that you created. Make sure that the Amazon S3 bucket name exactly matches the name of the hosted zone for your apex domain.
For Routing policy, choose Simple.
For Evaluate Health Target, choose No.
- Choose Create Records.
Confirm the redirection
To confirm the redirection, open your apex domain in a browser. Or, run the following curl command to check the response headers:
curl -i -s example.com | grep -E "HTTP|Location"
Location: http://www.example.com/
Example output:
curl -i -s example.com | grep -E "HTTP|Location" HTTP/1.1 301 Moved Permanently
Location: http://www.example.com/
Note: A successful redirection returns the HTTP 301 status code.
Related information
Redirect requests for your bucket's website endpoint to another bucket or domain