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

こ雲淡風輕ζ 提交于 2020-11-27 19:42:47

问题


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


回答1:


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.




回答2:


answer for this

  1. create www.example.com s3 bucket and set all code in this bucket
  2. create example.com s3 bucket and set redirect to www.example.com said by 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. for example.com point alias s3 bucket of example.com

Thanks for helping its works for me.



来源:https://stackoverflow.com/questions/37000416/how-to-redirect-non-www-to-www-in-aws-s3-bucket-and-cloudfront

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!