HTTPS redirect from a naked domain (example.com) to a full domain 'www.example.com' without an error?

10,699

Solution 1

You can put CloudFront in front of your s3 bucket and have CloudFront terminate the SSL connection. HTTPS is free when using SNI.

Steps:

  • create distribution and configure ssl, with the origin being your s3 website redirect bucket.
  • set the cname to be your naked domain
  • update route 53 to point to this distribution

Solution 2

Quite simply, you can't do what you are trying to do with S3, because the S3 web site endpoints offered by S3 do not support https.

DNS can't redirect web browsers, of course, so Amazon has a simple solution that leverages an S3 bucket with no content, and just a blanket redirect to another domain, as a helper mechanism to allow Route 53 to accomplish the task of redirecting the browser.

But the example.com → www.example.com redirection capability of S3 is http only.

Share:
10,699

Related videos on Youtube

Eki Eqbal
Author by

Eki Eqbal

Something about myself :) ®║▌│█│║▌║││█║▌║▌║▌ OFFICIAL Stackoverflow CELEBRITY ✔ Verified Official Page! ✔ Stackoverflow Certified Sorry, im too complicated to be described in a couple of words. Im a puzzle, yes indeed. :)

Updated on September 18, 2022

Comments

  • Eki Eqbal
    Eki Eqbal almost 2 years

    I'm trying to Redirect non-www requests to www on Amazon Route 53.

    I made an S3 bucket with the name of the naked domain and configure the bucket properties to redirect from example.com to www.example.com, and then in Route 53 create an alias for the naked domain name that points to that S3 bucket based on the following :

    Redirect non-www requests to www on Amazon Route 53

    It worked great for me, except for the HTTPS.

    Right now I can't access https://example.com for some reason.

    Any help would be highly appreciated.

    • Admin
      Admin over 9 years
      What is the problem you are having? "some reason" doesn't describe anything.
    • Admin
      Admin over 9 years
      I am trying to send naked domain traffic to www. I am using Amazon Route53 for DNS. I set up an S3 bucket and an Alias record to route naked domain traffic to www. That is working fine. The issue is that since I serve all content over https, if I go directly to example.com the browser cannot establish the necessary connection to the server and therefore doesn't even issue an HTTP request. Therefore I am not redirected to the www domain and instead the request fails.
    • Admin
      Admin over 9 years
      @MichaelHampton to summarize, here are the possible scenarios and results: 1: Enter example.com -> successful redirect to example.com 2: Enter www.example.com -> successful example.com 3: Enter example.com -> ERROR
    • Admin
      Admin over 9 years
      But what is the error?!
    • Admin
      Admin over 9 years
      The error is that we can't even access the page. As for example Chrome gives "Google Chrome's connection attempt to example.com was rejected. The website may be down, or your network may not be properly configured."
    • Admin
      Admin over 9 years
      Are your DNS A records correctly configured for both domains?
  • Eki Eqbal
    Eki Eqbal over 9 years
    Thanks for your help. Is there any workaround for this? I mean I'm sure I can do something here. How about @imperalix comment and using CloudFront to terminate the s3 bucket ?
  • Michael - sqlbot
    Michael - sqlbot over 9 years
    @EkiEqbal @imperialix is correct, you could use Cloudfront, assuming your visitors are using modern browsers with SNI capability. You'd also need to configure Cloudfront to pass the Host: header to the origin, and you'd have to use the S3 website endpoint as a custom origin, not as what Cloudfront calls an "S3 origin" (since that doesn't hit the web site endpoint).
  • imperalix
    imperalix over 9 years
    stackoverflow.com/a/24876361/1074480 does a good job of going into more details. Let me know if these steps don't work for you.