How to Redirect Non-WWW to WWW for My Website?

0
18
Asked By CuriousCactus91 On

Hey everyone! I'm looking for some help with setting up a redirect for my website, which we'll call "mywebsiteyay.com". I've created a certificate that covers both "mywebsiteyay.com" and "www.mywebsiteyay.com" and I'm using CloudFront with S3 as the backend to host my files, plus Route 53 and ACM Cert Manager for the records.

What I want to achieve is a seamless redirect from "mywebsiteyay.com" to "www.mywebsiteyay.com". I know it's possible, as so many sites do it, but I'd like guidance on the best way to set this up without having to use a Lambda function that might incur costs for every visitor. Should I handle this on the front-end, back-end, or is there a better practice? Any insights would be greatly appreciated!

3 Answers

Answered By SmartyPants01 On

You can also check out the AWS documentation for more details. It covers how to set up redirects in S3, and it might give you the specifics you need for configuring everything properly. Here's a useful link: https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-page-redirect.html.

Answered By CloudGuru23 On

You actually need two CloudFront distributions to make this work correctly.

**Distribution #1:** For www.mywebsiteyay.com
- Set it up to use your main S3 bucket where all your content is hosted.
- Add a CNAME for www.mywebsiteyay.com and use your ACM certificate here.

**Distribution #2:** For mywebsiteyay.com
- This should point to a second S3 bucket that’s configured for static website hosting, specifically to handle redirections.
- Make sure it has the same ACM certificate.

For the redirect bucket, you can add a static website hosting routing rule that directs traffic to www.mywebsiteyay.com with a 301 status. This setup is pretty low-cost since the redirect bucket’s traffic is minimal.

Answered By SandySols On

You can accomplish this using a combination of S3 and a CloudFront function. The S3 bucket can manage the static redirect, and the CloudFront function can help preserve URL paths when redirecting from non-www to www. So, for example, a request to https://page.com/things would redirect to https://www.page.com/things seamlessly.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.