I have a static website https://www.example.com
running on S3 behind Cloudfront. Cloudfront is used to enable https
.
I am currently redirecting traffic from http://example.com
(http
) to https://www.example.com
using bucket redirects.
How do I redirect traffic from https://example.com
(https
) to https://www.example.com
?
2
Answers
Use CloudFront Functions (JavaScript function executed by CloudFront at all of its edge locations) to 301 redirect to www if www is not in the hostname. Here is an example 302 redirect for reference — https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/redirect-based-on-country
If you use route53 as a DNS this is possible by creating an alias for your cloudfront distribution.
Its described in this knowledge center support article:
https://aws.amazon.com/premiumsupport/knowledge-center/route-53-redirect-to-another-domain/