{"id":18623586,"url":"https://github.com/codica2/redirect-s3-cf","last_synced_at":"2025-11-03T18:30:26.265Z","repository":{"id":98303674,"uuid":"235048285","full_name":"codica2/redirect-s3-cf","owner":"codica2","description":"This guide will show you how to redirect non-www requests to www with S3 and CloudFront.","archived":false,"fork":false,"pushed_at":"2020-01-20T08:28:21.000Z","size":622,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-27T05:24:51.685Z","etag":null,"topics":["aws","non-www","redirect","s3","www"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codica2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-20T08:01:48.000Z","updated_at":"2020-01-20T09:53:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"531d6925-bb15-47b7-9447-982d1c44780d","html_url":"https://github.com/codica2/redirect-s3-cf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fredirect-s3-cf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fredirect-s3-cf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fredirect-s3-cf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fredirect-s3-cf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codica2","download_url":"https://codeload.github.com/codica2/redirect-s3-cf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239418574,"owners_count":19635208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","non-www","redirect","s3","www"],"created_at":"2024-11-07T04:25:08.809Z","updated_at":"2025-11-03T18:30:26.216Z","avatar_url":"https://github.com/codica2.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eRedirect non-www to www with S3 and CloudFront\u003c/h1\u003e\n\n![](gitlab-www-banner.jpg)\n\nIf you want to redirect (non-www to www) to your static website hosted on S3 and delivered by CloudFront, this guide is for you.\n\n## Prerequisites\n\nWe will use such tools as:\n\n* [Amazon S3](https://aws.amazon.com/s3/) \n* [Amazon Certificate Manager](https://aws.amazon.com/ru/certificate-manager/)\n* [Amazon CloudFront](https://aws.amazon.com/ru/cloudfront/) \n* [Amazon Route53](https://aws.amazon.com/ru/route53/) \n\n![](gitlab-www.jpg)\n\n\n## Prepare the S3 buckets \nAt first, you need to create your S3 buckets. The main bucket name will be ``www.yourdomain.com``, the second one will be ``yourdomain.com``. When completed - upload static content to your main bucket, then complete static website hosting.\n\n![](s3-config.jpg)\n\nFor ``yourdomain.com`` named bucket use these settings:\n\n![](s3-redirect.png)\n\n## Get certificates for your domain\n\nChange your region to ``us-east-1`` and go to Amazon Certificate Manager, reqest certificates for both of your domain names ``www.yourdomain.com``and ``yourdomain.com``. Don't forget to create CNAME records in Route53.\n \n## Configuring CloudFront\n\nAfter getting certificates, go to CloudFront and create two ditributions. For Origin Domain Name use the S3 endpoint, **don't use** the autocompleted variant.\n\n![](cf-domain.png)\n\nFor Viewer Protocol Policy use Redirect HTTP to HTTPS.\n\n![](cf-redirect.png).\n\nCNAME for the main CloudFront distibution is going to be ``www.yourdomain.com`` with your www certificate. \n\n![](cf-cname.png)\n\nCNAME for the second CloudFront distibution is going to be ``yourdomain.com`` with your non-www certificate.\n\n![](cf-cname-non-www.png)\n\nDisable CloudFront caching.\n\n![](cf-caching.png)\n\n## Configuring Route53\n\nFor ``www.yourdomain.com`` create A record with alias to CloudFront address according to www domain.\n\n![](r53-www.png)\n\nFor ``yourdomain.com`` create A record with alias to CloudFront address according to non-www domain.\n\n![](r53-non-www.png)\n\n\n## License\nCopyright © 2015-2020 Codica. It is released under the [MIT License](https://opensource.org/licenses/MIT).\n\n## About Codica\n\n[![Codica logo](https://www.codica.com/assets/images/logo/logo.svg)](https://www.codica.com)\n\nThe names and logos for Codica are trademarks of Codica.\n\nWe love open source software! See [our other projects](https://github.com/codica2) or [hire us](https://www.codica.com/) to design, develop, and grow your product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodica2%2Fredirect-s3-cf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodica2%2Fredirect-s3-cf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodica2%2Fredirect-s3-cf/lists"}