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 Answers
1
Accepted Answer

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
answered 10 months ago
profile picture
EXPERT
reviewed a day ago
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.

answered 10 months ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions