I am attempting to use AWS S3 Static Website Redirect to allow redirects from an Apex domain (example.com) to the www.example.com domain.
I used the following guide https://medium.com/faun/redirect-naked-domain-to-www-with-https-on-aws-route-53-e620e4ce989d
In Route53, I have created an A record for the apex domain example.com
example.com A Simple s3-website-eu-west-1.amazonaws.com.
The www.example.domain
points to a cloudfront distribution which distributes my website.
The cloudfront domain will redirect all HTTP traffic to HTTPS
www.example.com A Simple *************.cloudfront.net.
In S3, I have created a bucket for example.com
and set it up to redirect all requests
[
The bucket is public and empty
The resulting behavior works for HTTP but times out for HTTPS
http://example.com -> https://www.example.com
https://example.com -> ETIMEDOUT
http://www.example.com -> https://www.example.com
https://www.example.com -> https://www.example.com
How can I fix this setup so that
https://example.com -> https://www.example.com
So, ideally you want all the followings to work:
1) https://example.com → https://www.example.com (naked to www)
2) http://www.example.com → https://www.example.com (http to https)
3) http://example.com → https://www.example.com (naked http to www https)
4) https://www.example.com → 🎉 actually show the content as the canonical URL! 🎉
Note that the requirement #3 above can be broken down into two steps, which would be a combination of #1 and then #2.
3B) http://example.com → http://www.example.com → https://www.example.com
All these →
s are a HTTP 301 Permanent Redirect.
So, you need 3 pieces here:
example.com → www.example.com
)http:// → https://
)This solution requires many pieces in AWS that should be all free! (or no additional cost)
Create a S3 Static Hosting Website and have it redirect to www.example.com.
Notes:
curl -v
).s3-website-us-west-2.amazonaws.com
)Go to https://us-west-2.console.aws.amazon.com/acm/home?region=us-west-2#/ (change your region to your preferred one) and request a public certificate. Make sure you put both example.com
and www.example.com
there. Verify it in Route 53.
Go to CloudFront and create a distribution with Viewer Protocol Policy of "Http => HTTPS redirect" and having its origin be the full URL of the S3 bucket above.
Notes:
Finally, go to your route53 DNS record and have it point the naked domain as A
record to the CloudFront distribution of step 3, which should be like d21k2s1234123.cloudfront.net
!
Tada!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With