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.
Enable static website hosting on example.org as its your primary bucket.
Then do the same thing for example.com and www . example.com, but this time enable Website Redirection (Redirect all request to another host name) and point them to example.org
Here’s an example for my configuration (want to redirect www to non-www)
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?
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.
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).