Search code examples
amazon-web-servicesamazon-s3amazon-cloudfrontamazon-route53

SEO Duplicate Content with AWS S3 with CloudFront Static Website


I've done a classical setup for a static website using S3, CloudFront and Route53, however I'm getting a maddening error I hadn't encountered before.

So there's 2 buckets, example.net and www.example.net, with the non-www one having the Static Hosting on and the actual files, the www one just the redirect to HTTPS.

On the Route53 side, I've got the A record for mysite.com as an Alias for the CloudFront distribution, with the www CNAME pointing back to mysite.com

The CloudFront distribution uses the non-www bucket as the origin, but lists as alternative both www and non-www sites, with the Redirect HTTP to HTTPS option on.

All of this successfully allows me to have the website functioning, but on the SEO side I'm having a duplicate content issue because all of the alias successfully resolve as so


http non-www address --> https non-ww address (HTTP to HTTPS, good)

https non-www address --> https non-www address (Straight HTTPS, good)


http www address --> https www address (Works, but fails redirecting to non-www domain)

https www address --> https www address (Works, but fails redirecting to non-www domain)


Everything I try seemingly breaks the www side (like removing the alias on the CloudFront distribution, or switching the CNAME for an A that points to the CloudFront URL). Thing is, I had done this previously with a GoDaddy DNS with the Forwarding feature, which from this answer I understand is a reverse proxy rather then a core DNS feature.

However, I found this medium article on how to use CloudFront as a reverse proxy, but I can't understand how to apply it to this scenario.

Can anyone help me, please?, thanks in advance!


Solution

  • If I understand your question correctly, you are basically saying both http www address and https www address should be redirecting to https non-www address.

    To reference the domain names easily, let's assume the www address is www.example.com, and the non-www address is example.com.

    Here is my proposed solution to you problem.

    1. Change the CNAME dns record of www.example.com to an ALAS record pointing to your non-www S3 bucket.

    2. Configure your non-www S3 bucket as a static website and let it redirect all incoming requests to example.com using https protocol.