S3 Static website is automatically redirecting from apex domain to www but can't find where that is configured

0

I have a static website running using S3, CloudFront, R53, and ACM.
I would like any http to redirect to https and the root domain to redirect to www in the browser.
One case does not work and I cannot figure out why.
Also, I don't remember explicitly configuring anything to redirect root to www but it does this automatically but only when using http.

https://www.example.com - Works
http://www.example.com - Works (Redirects to https://www.example.com)
http://example.com - Works (Redirects to https://www.example.com)
https://example.com - Connection Timeout

R53:
www.example.com CNAME -> CloudFront Distro Url

CloudFront:
Alternate domain names:
exmaple.com
www.example.com
Origins: Http Only, S3 bucket
Behavior: Redirect HTTP to HTTPS

S3:
Bucket name: example.com
Hosting Type: Host a static website

AWS Certificate Manager:
Domains:
*.example.com
example.com

2 個答案
1
已接受的答案

Many browsers today will add www. to your domain when you enter just the domain.com. That may be why the domain.com works when you do HTTP:// but not when you do https://.

You can validate this by using curl command like so:

curl HTTP://example.com

If it returns an error, then this is probably what is happening.

You can follow this tutorial and you can then redirect all HTTP and https traffic for example.com and www.example.com to your S3 bucket as you like.

Hope this helps!

profile picture
已回答 1 年前
profile picture
專家
已審閱 1 個月前
0

Thanks for the help Carlos.

Good call! Yes, it appears the browser was adding www. curl works for www but not the root domain, which makes sense now.

I looked at that link and still being very new to AWS, is there another tutorial that instead uses CloudFront? I'm a bit concerned on the potential cost of all these services just to host a static website when my trail runs out.

I've many many posts that suggest I can redirect root domain to www using an A record alias that points to the CF distro url using Route53 but I have not been able to get that to work.

已回答 1 年前
  • Unfortunately Route 53 does not allow CNAMEs for the apex of the domain. You would have to use a service like redirect.pizza which can do that for you for free.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南