Set up WWW Domain Redirect

From @jayair on Mon Apr 10 2017 01:09:47 GMT+0000 (UTC)

Link to chapter - http://serverless-stack.com/chapters/setup-www-domain-redirect.html

Copied from original issue: https://github.com/AnomalyInnovations/serverless-stack-com/issues/66

From @pjamieson on Mon Jul 03 2017 20:01:42 GMT+0000 (UTC)

Rather than create a second CloudFront Distribution, why not just add the alias www.[my-domain].com to the Route53 Record Sets for [my-domain]–pointing to the first distribution–then add www.[my-domain].com to that first distribution’s Alternate Domain Names? That seems to work fine. Am I missing something?

From @jayair on Mon Jul 03 2017 20:33:01 GMT+0000 (UTC)

@pjamieson The reason we set up a redirect on our alternate domain is for SEO purposes. Not necessarily for ranking but because we don’t want two versions of our domain active. By re-directing one (the www or apex domain) to the other we are telling the search engines to use one as opposed to both. I hope that makes sense.

From @pjamieson on Mon Jul 03 2017 20:45:12 GMT+0000 (UTC)

Thanks, @jayair. That makes sense.

From @jayair on Mon Jul 03 2017 21:12:26 GMT+0000 (UTC)

@pjamieson Just added a small note to the chapter https://github.com/AnomalyInnovations/serverless-stack-com/commit/9b67ea34af928bf38025b882b2e6181a6df082cf.

From @x11joe on Sat Nov 11 2017 12:02:09 GMT+0000 (UTC)

I’m getting the following error on this step, com.amazonaws.services.cloudfront.model.CNAMEAlreadyExistsException: One or more of the CNAMEs you provided are already associated with a different resource. (Service: AmazonCloudFront; Status Code: 409; Error Code: CNAMEAlreadyExists; Request ID: e21a6bde-c6d7-11e7-9415-837f645450a5), any ideas?

My bucket name is definitely different, so not sure…

From @jayair on Sat Nov 11 2017 19:37:26 GMT+0000 (UTC)

@x11joe This usually has to do with a CloudFront distribution having a CNAME already listed as the one you are trying to add. On which screen are you seeing this?

From @x11joe on Sat Nov 11 2017 20:10:14 GMT+0000 (UTC)

I am seeing this on the part where you say … Scroll down to the Alternate Domain Names (CNAMEs) and use the www version of our domain name here.

It shows up at the bottom, I’ll try and get a screenshot.

Well… this is going to sound stupid but I tried just now and its working all the sudden?? Maybe this happened because I was doing test with the domain name prior on another serverless tutorial and it takes like 24 hours for it to remove it’s self? Not sure. Maybe this post will help someone.

From @jayair on Sat Nov 11 2017 20:14:39 GMT+0000 (UTC)

@x11joe Yeah this can happen. Both the domain setting part and the CloudFront distributions take some time to apply their changes.

From @johnnybigert on Mon Nov 27 2017 15:09:01 GMT+0000 (UTC)

I just registered a domain (let’s call it “mysite.com”) and it shows the Notes app correctly. The s3 url and the cloudflare distribution url also show the Notes app. When trying to get the redirect from www.mysite.com to work, I get the following behavior:

http://www-xxx-notes-app-client.s3-website-us-east-1.amazonaws.com redirects correctly to mysite.com. However, http://www.mysite.com/ and xxx.cloudfront.net (which is the www cloudfront distribution url) both give

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
  <Code>AccessDenied</Code>
  <Message>Access Denied</Message>
  <RequestId>xxx</RequestId>
  <HostId>xxx</HostId>
</Error>

I have looked through the settings of the s3 redirect bucket, the www cloudfront distribution and the hosted zone record sets and they seem correct. Any ideas what to do?

2 Likes

I’ve just run into this myself and was wondering if you resolved it.

Thanks

Which issue are you referring to?

I have exactly the same problem, did you find the solution?
many thanks.

I think @rjison9000 refers to the ‘Access Denied’ problem.

Whats the issue you are having?

I have already solved my problem with this https://github.com/AnomalyInnovations/serverless-stack-com/issues/66#issuecomment-347220022

thank you very much

1 Like