How To redirect naked domain to full domain in AWS

  • Home
  • /
  • How To redirect naked domain to full domain in AWS
How To redirect naked domain to full domain in AWS

How To redirect naked domain to full domain in AWS

A w s 01 Jun 2020

In this article we will see the steps to redirect naked domain to full domain in AWS. When you create a website which is hosted in S3, CloudFront and Route 53 your naked domain does not get redirected to full domain automatically. To redirect, you need to follow below steps

Step 1: Create a S3 Bucket
  • Login into your AWS Management Console and go to Amazon S3
  • Create a new bucket for the naked domain say example.com
  • Click on the newly created bucket for naked domain, Then navigate to –> Properties –> Static website hosting –> Redirect requests
  • Fill Target bucket or domain with the full domain name www.example.com
  • Click on Endpoint and validate redirection is happening as expected
  • Click on the newly created bucket for naked domain –> Permissions –> Block public access –> - Here make sure Block all public access is ‘On’ since we don’t need any kind of public access to this bucket.
Step 2: Create CloudFront distribution
  • Copy the endpoint from static webhosting and use it to create a new CloudFront distribution. Remember here “Origin Domain Name” should the endpoint from static webhosting of s3 and not the s3 bucket itself.

  • Select Redirect HTTP to HTTPS in Viewer Protocol Policy

  • Select Yes in Compress Objects Automatically

  • Fill Alternate Domain Names (CNAMEs) with naked domain name example.com

  • Select Custom SSL Certificate (example.com): in SSL Certificate and select the certificate which was created for your domain

  • Fill Comment with naked domain name example.com.

  • Click Create Distribution

  • After CloudFront distribution creation is complete, Copy the Domain Name from CloudFront distribution

Step 3: Update Route 53
  • Go to Route 53 –> Click Hosted zones –> Click the Hosted zone which we created

  • Add a record set for the naked domain name example.com

Name www
Type A
Alias Yes
Alias Target Domain name from CloudFront distribution
Routing Policy Simple
Evaluate Target Health No

Now you should be able to access your website using naked domain example.com also. Please note DNS changes will take a few minutes to get reflected.

Share: