skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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:

    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).http://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/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search