1

I have a static website hosted on s3 with cloudfront distribution. I've found tons of answers on redirecting to www with only route 53 in front of s3, but nothing on how to do it with cloudfront.

I've tried a bunch of different things but none of them 301 redirect to www, only alias.

Akababa
  • 133
  • 1
  • 7

1 Answers1

5

The solution is the same as with Route 53 and S3, you just configure CloudFront in the middle, so Route 53 points to CloudFront and CloudFront points to S3.

You'll have two buckets and two CloudFront distributions when you're done, one for the www and one for the bare domain.

Michael - sqlbot
  • 22,658
  • 2
  • 63
  • 86
  • 2
    Why do I need cloudfront in front of the bare domain bucket? – Akababa Nov 17 '17 at 04:46
  • 1
    Technically, you only need it if you want to be able to accept and redirect requests for `https://example.com`, which is probably a good idea, and CloudFront will cache the redirects closer to your viewers... but your entire question asked about how to do this with CloudFront, so I didn't answer how to do it without. To redirect a bare domain to www *using CloudFront*, you put a bucket behind a second CloudFront distribution to do the work of generating the redirect. – Michael - sqlbot Nov 17 '17 at 12:37