Sig
Sig

Reputation: 5916

Redirect traffic with CloudFront

I have deployed a static site with AWS S3, CloudFront, and Route53. The site works fine with the apex url (example.com).

Now I wish to add also www.example.com so, I have created an empty bucket and redirected all the traffic to the first bucket.

What should I do on CloudFront? Create a distribution for the empty bucket?

Thanks

Upvotes: 1

Views: 532

Answers (1)

Christian
Christian

Reputation: 7131

You should create a new CloudFront distribution. The trick here is to NOT use the proposed bucket values, but use the endpoint directly.

In example, this is my bucket endpoint:

 redirect-jekyll.io.s3-website-eu-west-1.amazonaws.com

An this would be the proposed endpoint which you SHOULD NOT use:

 redirect-jekyll.io.s3.amazonaws.com

The difference is, only the endpoint would send you the redirect. You can receive your endpoint address by going to the S3 console and look at the properties. Setting that, will make your CloudFront distribution using a "Custom target", which is perfectly find for your use case.

Upvotes: 3

Related Questions