I followed the accepted answer here: Cloudfront redirect www to naked domain with ssl
Here is what I did:
- Create two S3 buckets named: example.com and www.example.com.
2.Turn on the Static Website Hosting on these two buckets.
3.Configure redirect in bucket www.example.com to bucket www.example.com. Protocol I chose https
4.For these buckets create two CloudFront Distributions. Each of this distributions point to corresponding bucket:
For Origin Domain Name provide bucket urls provided in Static Website Hosting section. The urls should have form (or similar): example.com.s3-website-us-west-1.amazonaws.com
On both distribution set HTTP to HTTPS redirect.
- Route 53 configure DNS by setting:
An Aias records for example.com to point to corresponding CloudFront distribution.
An CNAME for www.xample.com to point to corresponding CloudFront distribution
The result:
http://www.example.com gets redirected to https://example.com
https://www.example.com gets redirected to https://example.com
This is the strange one: When I enter example.com directly on my browser, I noticed that it gets redirected very quickly to http://www.example.com or (or https://www.example.com, it's too fast, I can't see it well), then immediately gets redirected to https://example.com. Why there is a double direction here? thx.