0

I followed the accepted answer here: Cloudfront redirect www to naked domain with ssl

Here is what I did:

  1. Create two S3 buckets named: example.com and www.example.com.

2.Turn on the Static Website Hosting on these two buckets.

3.Configure redirect in bucket www.example.com to bucket www.example.com. Protocol I chose https

4.For these buckets create two CloudFront Distributions. Each of this distributions point to corresponding bucket:

For Origin Domain Name provide bucket urls provided in Static Website Hosting section. The urls should have form (or similar): example.com.s3-website-us-west-1.amazonaws.com

On both distribution set HTTP to HTTPS redirect.

  1. Route 53 configure DNS by setting:

An Aias records for example.com to point to corresponding CloudFront distribution.

An CNAME for www.xample.com to point to corresponding CloudFront distribution

The result:

  1. http://www.example.com gets redirected to https://example.com

  2. https://www.example.com gets redirected to https://example.com

  3. This is the strange one: When I enter example.com directly on my browser, I noticed that it gets redirected very quickly to http://www.example.com or (or https://www.example.com, it's too fast, I can't see it well), then immediately gets redirected to https://example.com. Why there is a double direction here? thx.

lola
  • 75
  • 1
  • 8
  • Please provide the actual hostname so we can duplicate what you're seeing. Otherwise, you can use your browser's developer tools or a browser extension (like [this one](https://chrome.google.com/webstore/detail/http-headers/nioieekamcpjfleokdcdifpmclkohddp?hl=en), for example) to easily see the actual chain of redirects. – Michael - sqlbot Dec 25 '17 at 19:28
  • You're awesome Michael. You're not only helping me but also teaching me how to debug the issue. Thanks you so much. – lola Dec 26 '17 at 11:06
  • You're awesome Michael. You're not only helping me but also teaching me how to debug the issue. Thanks you so much. This is what I was seeing: Get h-ttp://www.example.com(Status: HTTP/1.1 301 Moved Permanently, Responder:Redirect from cloudfront)--> "Get h-ttps://www.example.com--->Get h-ttps://example.com. This is strange. I did configure on the s3 bucket property redirecting h-ttp://example.com to h-ttp://www.example.com before. But I corrected it. Now, my website content is stored on bucket example.com and bucket www.example.com do a redirection to https://example.com. – lola Dec 26 '17 at 11:12
  • sorry that I had to add "-" to the url, otherwise, stackoverflow takes the word out :-( – lola Dec 26 '17 at 11:16
  • you can avoid that by using backticks `\`` to quote text that you want to be treated literally: `http://example.com`. – Michael - sqlbot Dec 27 '17 at 00:27
  • The double redirection from `http://www.example.com` → `https://www.example.com` → `https://example.com` is expected if you configured the www CloudFront distribution to "redirect all requests to https," which it appears you did. It does that redirection, first. Then your second request passes through the www CloudFront and hits the www bucket which finally redirects you to the bare domain CloudFront. – Michael - sqlbot Dec 27 '17 at 00:34
  • Where does this leave you? Is it working now or is there still a problem? – Michael - sqlbot Dec 27 '17 at 00:35
  • Hi Michael, it's still a problem. I understand that `http://www.example.com` → `https://www.example.com` → `https://example.com` is expected . The issue is why http://iris.live gets redirected to http://www.iris.live first? Shouldn't it be redirected directly to https://iris.live? – lola Dec 27 '17 at 09:30

0 Answers0