Code Monkey home page Code Monkey logo

redirect-s3-cf's Introduction

Redirect non-www to www with S3 and CloudFront

If you want to redirect (non-www to www) to your static website hosted on S3 and delivered by CloudFront, this guide is for you.

Prerequisites

We will use such tools as:

Prepare the S3 buckets

At 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.

For yourdomain.com named bucket use these settings:

Get certificates for your domain

Change your region to us-east-1 and go to Amazon Certificate Manager, reqest certificates for both of your domain names www.yourdomain.comand yourdomain.com. Don't forget to create CNAME records in Route53.

Configuring CloudFront

After getting certificates, go to CloudFront and create two ditributions. For Origin Domain Name use the S3 endpoint, don't use the autocompleted variant.

For Viewer Protocol Policy use Redirect HTTP to HTTPS.

.

CNAME for the main CloudFront distibution is going to be www.yourdomain.com with your www certificate.

CNAME for the second CloudFront distibution is going to be yourdomain.com with your non-www certificate.

Disable CloudFront caching.

Configuring Route53

For www.yourdomain.com create A record with alias to CloudFront address according to www domain.

For yourdomain.com create A record with alias to CloudFront address according to non-www domain.

License

Copyright © 2015-2020 Codica. It is released under the MIT License.

About Codica

Codica logo

The names and logos for Codica are trademarks of Codica.

We love open source software! See our other projects or hire us to design, develop, and grow your product.

redirect-s3-cf's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.