Home How to redirect non-www traffic to www for site hosted on EC2 instance behind CloudFront?
Reply: 0

How to redirect non-www traffic to www for site hosted on EC2 instance behind CloudFront?

user5012 Published in September 19, 2018, 3:18 am

I host a site on a single EC2 instance behind CloudFront and need to redirect all non-www traffic to www.

From other Q/A here on SO I was able to configure an A record on Route53 to redirect traffic from example.com to www.example.com. However, this only works for http traffic, not https traffic.

How can I get the https traffic for the naked (non-www) URL to redirect to my canonical URL https://www.example.com?

I know there are similar questions asked already, but I don't see any with my same configuration (most are for sites hosted in an S3 bucket or for redirecting from www to non-www).

Current URL handling situation

https://www.example.com - Canonical URL for the site, handled by CloudFront
http://www.example.com - CloudFront redirects to https://www.example.com
https://example.com - Unreachable!!!
http://example.com - Route53 redirects to https://www.example.com via S3 bucket

Other details

The CloudFront distribution uses an AWS-generated certificate which covers the following domains:


Alternate Domain Names (CNAMEs) listed in the distribution are:


Route53 has the following A records:

www.example.com -> CloudFront distribution
example.com -> S3 bucket, configured to redirect to www.example.com
share|improve this question

2 Answers 2

active oldest votes
up vote 3 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.384888 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO