How to redirect domain with prefix www in AWS Route 53

16,937

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
16,937
mbdvg
Author by

mbdvg

Updated on June 05, 2022

Comments

  • mbdvg
    mbdvg almost 2 years

    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?

  • Juan
    Juan almost 8 years
    If you are like me, using a CNAME to point the www.domain.com to the host, and trying to create an Alias for the naked domain: the name of the bucket MUST BE your naked domain name (eg: domain.com). Then, create an A record, mark it as an alias and select your bucket form the dropdown. And thats it. It should work right after clicking save
  • François Gautier
    François Gautier over 7 years
    When accessing cstructor.com, you will NOT get to www.cstructor.com. It points to the same load-balancer, but it's not what was asked
  • Jim Moriarty
    Jim Moriarty over 7 years
    Correct, but this is a reasonable solution.
  • netpoetica
    netpoetica about 6 years
    Can you keep your files in the naked bucket and then redirect to www?
  • Gary Vernon Grubb
    Gary Vernon Grubb over 5 years
    This worked for me. I am using it with cloud front. Thanks.
  • Aidin
    Aidin about 3 years
    @netpoetica what is the point of hosting the files in naked? If you don't like files belonging to www, you can create a cdn.domain.com. Let the naked be its own dumb things, solely serving redirect to www.