Redirect non-www requests to www on Amazon Route 53

flavian asked:

I want to redirect all requests from example.com to www.example.com.

Preferably, this should happen at DNS level. I tried using PTR records, but that simply fails, returning a 404.

wwww.example.com is an ALIAS for an Elastic Load Balancer.

What’s the simplest way to achieve this?

My answer:


If you’re already using Route 53, you can use their proprietary alias “record” to solve this problem. With standard DNS, you cannot do this at all and you have to have a web site send a 301 redirect. Of course, you still need to send the 301 redirects or deal with the fact that some requests will come in without the www (though you should send 301s for SEO reasons).

Probably the easiest way to do this is to set up an S3 bucket with the name of the naked domain and configure the bucket properties to redirect from example.com to www.example.com, and then in Route 53 create an alias for the naked domain name that points to that S3 bucket.

From the Comments

To enhance the answer, here is what we did to get this working:

  • Set up bucket – doesn’t matter what its name is and must allow public.
  • In bucket, click properties and click static website hosting. Click redirect all requests to another host name and enter the site you want traffic to go to.
  • Copy the endpoint of the bucket name and go to the hosted zone in the Route53 console and add a CNAME with Alias No to the url that you need to be redirected from and paste the bucket endpoint as its value.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.