How to set up your Amazon S3 / CloudFront hosted Jekyll website to resolve with www and without www

WWW I don’t like you

I’ve never liked prefacing websites with www. This probably goes back twenty years to when I first started building servers before sending them off to cheap co-lo hosting sites. Way back in the Wild West days of the Internet, last century!

My problem with www is that it is inefficient. Websites work just fine without a www. URLs look nicer without a www prepending them. Setting up websites to respond when someone types www at the start of a domain name actually requires more work than setting up a website so it only resolves without the www.

My dislike of www may be odd, possibly even comical, but it comes from a good place. Any inefficiency in web dev needs to be improved. This is how the world of the Internet makes progress. I can’t change the world by myself, but by refusing to use www on my own sites I’m making a stand in my own small way.

It is a fact that some people will try and access any website by prefacing it with a www while typing it into an address bar. So as long as direct traffic is important then it is worth setting up a system that redirects www traffic to non www domains.

Apex vs naked domains

For clarity this is an Apex domain example.com

For clarity this is a naked domain example.com

This is a stinking crappy www domain www.example.com

Clear? Then let’s proceed.

How to resolve a www domain to a naked domain

There are lots of good tutorials about setting up Jekyll sites to redirect to naked domains from www requests. Because the way I host Jekyll specifically uses Amazon Route 53 (for DNS), Amazon S3 (for storage) and Amazon CloudFront (for serving) I’m going to stick with issues that specifically related to this hosting setup. I can’t be the only person to shove everything Jekyll in the direction of Amazon AWS.

Rather than writing a massive tutorial about how to redirect traffic from one domain variant to another I’m going to tell you the things the other tutorials didn’t mention. The things I had to find out the difficult way.

  • Some older tutorials state that you MUST set up your Amazon S3 hosting Jekyll site to use www. This is quite simply not true. The site you are reading right now is hosted on Amazon S3 without www.

  • When you request a free SSL certificate through AWS certificate management you must request a wild card *.example.com and a apex / naked domain version example.com

  • If you are using Route 53 for your DNS, and why wouldn’t you, then you need to add A and AAA for www and naked domains. When setting the naked domains leave the ‘name’ box at the top of the setup section empty. source

  • In CloudFront make sure you have both the www and naked domains set in the ‘Alternative Domain Names (CNAMEs)’ entry box in the distribution settings.

  • There are some tutorials and forum / Stack Exchange instructions that claim you need to set up a second Amazon S3 bucket to redirect www traffic to a naked domain. I did not find this to be the case.