Home > OS >  How do I redirect https requests in AWS (static page on s3 behind cloudfront)
How do I redirect https requests in AWS (static page on s3 behind cloudfront)

Time:08-26

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?

CodePudding user response:

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

CodePudding user response:

If you use route53 as a DNS this is possible by creating an alias for your cloudfront distribution.

Use Route 53 alias records to map one domain to another domain. This method can be used only to redirect resources that are valid alias targets. For example:

  • example.com alias example.cloudfront.net

  • www.example.com alias example.cloudfront.net

If you're using an HTTPS endpoint, then confirm that the DNS target supports an alternate domain name. For example, if you're using Amazon CloudFront, see Using custom URLs by adding alternate domain names (CNAMEs).www.example.com alias

Its described in this knowledge center support article: https://aws.amazon.com/premiumsupport/knowledge-center/route-53-redirect-to-another-domain/

  • Related