0
votes

I have a problem with a website I'm hosting in S3 and distributing via CloudFront.

In S3 have created 2 buckets, one for example.com and one for www.example.com both set to static webhosting and the www.example.com forwarding to example.com

In Route 53 I have a hosted zone for both sites with A record to the Cloudfront distribution

In CloudFront I have a distribution with CNAME/Alternate Domain Names for both www.example.com and example.com and I also have origin paths for both the s3 bucket paths for both www.example.com and example.com

When I browse to https://example.com it works fine When I browse to https://www.example.com it doesn't load and I get an error: Server IP address could not be found

What am I missing?

1
I have a hosted zone for both sites ...so you have one hosted zone, or two? - Michael - sqlbot

1 Answers

0
votes

You should make only 1 cloudfront distribution, and then redirect traffic from www.example.com to example.com (or vice versa). See this link.

Edit: got some clarification on the issue from the comment. The way I have it setup for one of my domains is the following:

S3 has redirect setup on www.example.com, redirect requests to example.com using https protocol

Cloudfront distribution (pointed at example.com bucket) has a behavior set for redirect all HTTP to HTTPS

I think if you have the redirect behaviour on cloudfront setup this way along with the S3 redirect, it should work.