Setting Up CloudFront with Forwarding

I purchased example.org through Route53, and setup a hosted zone, cloudfront, and s3 bucket. The hosted zone is configured to use cloudfront which pulls content from the s3 bucket and the bucket is configured to “Restrict Bucket Access” from the cloudfront configuration.

I also have “Redirect HTTP to HTTPS” selected in cloudfront and I setup www.example.org in the cloudfront’s CNAME.

I am able to go to the site’s official location at https://www.example.org and http://www.example.org will 301 redirect me there.

What is the best way to setup AWS to throw 301 redirects to https://www.example.org for the following requests:


Related discussions:

Here’s an example for my configuration (want to redirect www to non-www)


bash-3.2$ curl -I www . streamwoop . com

HTTP/1.1 301 Moved Permanently

x-amz-request-id: xx

Location: http :// streamwoop.com /

Really need 301’s? You could add them all as CNAMEs to your distribution…

In the past I would setup buckets for all of them and have them redirect to my preferred domain, but it seemed sloppy and the https links wouldn’t work. Would the https links work with this method?

I guess it doesn’t have to be 301 redirects, but if I add them as CNAMEs would there be any redirection?

If you want HTTPS to work, you have to put the bucket behind Cloudfront. Be sure to use the S3 Web URL, not the REST URL that Cloudfront will try to set up automatically. Only the Web URL will return the 301 redirect, the REST URL will return a 404.

You’ll probably want a CF distribution dedicated to the redirects, but you’ll only need one and only one bucket. You’ll just want all of the names in the CNAME list on the distribution, and you’ll need all of the names on the SSL certificate. The default settings on Cloudfront don’t forward the Host header, so S3 will won’t know the difference.

There won’t be any redirection with just a CNAME.

That’s what I figured. I guess I can do it with CNAMEs, use javascript to redirect, and setup a canonical link tag. Is this my best approach?

Googlebot doesn’t understand JS redirects and doesn’t like duplicate content though. HTTP redirects is what you want.

But they do understand the canonical link tag, don’t they? I agree, HTTP redirects would be preferred over JavaScript redirects, but if I’m using CNAMEs how would I send only certain some domains the HTTP redirect and not the correct domain one?

canonical links would help (afaik), not sure how it rates compared to permanent redirects (its not quite the same but at least you show intent by noting the canonical url).