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
Target bucket or domainwith the full domain name
- Click on
Endpointand 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 accessis ‘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.
Redirect HTTP to HTTPSin Viewer Protocol Policy
Yesin Compress Objects Automatically
Alternate Domain Names (CNAMEs)with naked domain name example.com
Custom SSL Certificate (example.com):in SSL Certificate and select the certificate which was created for your domain
Commentwith naked domain name example.com.
After CloudFront distribution creation is complete, Copy the
Domain Namefrom 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
|Alias Target||Domain name from CloudFront distribution|
|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.