Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect non www to www in aws s3 bucket and cloudfront

I know how to redirect/rewrite non-www to www using .htaccess in apache server. But I have no clue, about s3 bucket, and CloudFront. I have hosted the website on an s3 bucket using CloudFront.

How do I redirect all http://example.com/ requests to http://www.example.com

like image 421
aviboy2006 Avatar asked May 03 '16 09:05

aviboy2006


2 Answers

  1. Create a www.example.com S3 bucket and place all the code in this bucket
  2. Create a example.com S3 bucket and set redirect to www.example.com as mentioned in https://aws.amazon.com/blogs/aws/root-domain-website-hosting-for-amazon-s3/
  3. Create CloudFront and configure with S3 bucket link of www.example.com and add cname entry only for www.example.com.
  4. In Route 53 for www.example.com point alias as CloudFront link related to S3 bucket
  5. In Route 53 for example.com point alias S3 bucket of example.com
like image 101
aviboy2006 Avatar answered Nov 12 '22 14:11

aviboy2006


There is a feature in S3 where you can to this. Select a bucket, in Properties under Static Web Hosting select Redirect all requests to another host name.

Read more here: https://aws.amazon.com/blogs/aws/root-domain-website-hosting-for-amazon-s3/

Update from comment: Add a cname in your domain setup for example.com to point to your bucket endpoint and a cname for your www.example.com to point to the cloudfront endpoint.

like image 40
Gustaf Avatar answered Nov 12 '22 13:11

Gustaf