Question:
I already have Cloud Front setup to redirect all calls to HTTPS protocol.
Now I want to forward “non www” to www. How can I achieve this with respect to the current setup?
I tried the one below, but it wasn’t successful as this one doesn’t take HTTPS redirection into consideration.
https://www.pbxdom.com/how-redirect-non-www-to-www-with-amazon-cloud-front-route-53-and-s3
URL doesn’t redirect www. Instead, it shows error message:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
1 2 3 4 |
AccessDenied |
Answer:
Here’s another way of solving the problem. I actually tried to do exactly what you did, and I could never seem to truly redirect the non wwww to the www when CloudFront was involved.
Once you set CloudFront to redirect all HTTP to HTTPS, it handles all of that redirection so you don’t need to worry about it. You can take it out of the logic equation.
You should have 4 “A” type records in your Route 53 for the domain (assuming you have IPv6 enabled in CloudFront):
- www.domain.com “A” alias record pointing to your CloudFront instance
- www.domain.com “AAAA” alias record pointing to your CloudFront instance
- domain.com “A” alias record pointing to your CloudFront instance
- domain.com “AAAA” alias record pointing to your CloudFront instance
And lastly, In the CloudFront “Alternate Domain Names (CNAMEs)” field in the general CloudFront configuration, make sure it contains the www and the non www. Do note that CloudFront changes actually take quite a while to propagate, so be deliberate and patient with your changes.
The end result of this is that both www and non www will work, without any apparent redirection from non www to www, but there is still HTTPS redirection.