This article assumes you want to redirect a www version of a domain (e.g. www.sushilkumar.ind.in) to the non-www root domain (e.g. sushilkumar.ind.in) with HTTPS, and using Amazon S3 static site redirect and CloudFront.
Before we start, there are a few important notes to keep in mind:
- In order to redirect via CloudFront we will have to configure an Amazon S3 bucket for redirect.
- If you are already using an Amazon S3 bucket for redirect and you want to enable the HTTPS redirect, then you need to use Amazon CloudFront. It’s not possible to use HTTPS on Amazon S3 with a custom domain.
- If you want the origin domain to redirect via HTTPS, then you MUST have a valid SSL/TLS certificate that covers that domain. You can use Amazon Certificate Manager to request a new certificate free of charge, or use an existing certificate if you already have one.
- If you want to redirect the root domain to www, then you must use a DNS hosting provider such as DNSimple that supports CNAME-like features for the root domain. You will need to point the root domain to the Amazon CloudFront distribution endpoint, and you can’t use a CNAME. At DNSimple we call it the ALIAS record.
- The redirect target doesn’t have to be hosted on Amazon S3 or Amazon CloudFront. For sushilkumar.ind.in, you can deploy your site sushilkumar.ind.in on Heroku, and use Amazon S3+CloudFront to redirect www.sushilkumar.ind.in to sushilkumar.ind.in.
To configure the redirect, follow the detailed instructions in this article. In the referenced article, the redirecting host name is the host name that will redirect, whereas the target host name is the target of the redirect.
For sushilkumar.ind.in, if you want to redirect http://www.sushilkumar.ind.in and https://www.sushilkumar.ind.in to https://sushilkumar.ind.in, then you will have to follow the steps detailed in the article and:
- Create a bucket called www.sushilkumar.ind.in, and setup the redirect to https://sushilkumar.ind.in
- Request or import a certificate for www.sushilkumar.ind.in
- Configure a distribution for www.sushilkumar.ind.in
- create a CNAME DNS record to point www.sushilkumar.ind.in to the Amazon CloudFront distribution endpoint
Instead, if you want to redirect http://sushilkumar.ind.in and https://sushilkumar.ind.in to https://www.sushilkumar.ind.in, then you will have to follow the steps detailed in the article and:
- Create a bucket called sushilkumar.ind.in, and setup the redirect to https://www.sushilkumar.ind.in
- Request or import a certificate for sushilkumar.ind.in
- Configure a distribution for sushilkumar.ind.in
- Create an ALIAS record to point sushilkumar.ind.in to the Amazon CloudFront distribution endpoint
If you should experience some issues, check the common errors section.