Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect domain with prefix www in AWS Route 53

I have a problem with domain hosting in Route 53.

I need to redirect from xyz.com to www.xyz.com, so I created a Hosted Zone on Route 53. I added an A record with the address of my ELB, and a CNAME with a name of www.xyz.com and value of my ELB address.

But this set up does not redirect my naked domain to my www prefixed domain. How do I solve this issue?

like image 463
mbdvg Avatar asked Apr 05 '13 11:04

mbdvg


3 Answers

This is currently not possible using only Amazon Route 53. Please have a look into this thread for additional information.

Also, please be aware that a "naked domain" (e.g. xyz.com) redirect should be handled in the HTTP layer, not in the DNS.

like image 196
Viccari Avatar answered Oct 21 '22 19:10

Viccari


I've gotten this to work using both S3 and CloudFront.

You need two buckets: www.yourdomainname.com and yourdomainname.com.

Keep your files in the www bucket. For the naked domain bucket properties, go to the "Static Website Hosting" section and select "redirect all requests to another host name", and enter www.yourdomainname.com.

like image 39
Oleg Vaskevich Avatar answered Oct 21 '22 18:10

Oleg Vaskevich


Following the steps below will resolve your problem:

  1. Create two buckets: one for example.com and one for www.example.com
  2. Setup example.com bucket to redirect to www.example.com
  3. Create two distributions: one using the example.com bucket and one using the www.example.com bucket (Use the corresponding domain for the CNAME)
  4. In route 53, A ALIAS example.com to the first CloudFront distribution and A ALIAS www.example.com to the second CloudFront distribution

After the DNS changes take effect, browse to example.com and it should redirect to www.example.com

like image 25
branah Avatar answered Oct 21 '22 18:10

branah