How to redirect domain with prefix www in AWS Route 53
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:
- Create two buckets: one for example.com and one for www.example.com
- Setup example.com bucket to redirect to www.example.com
- Create two distributions: one using the example.com bucket and one using the www.example.com bucket (Use the corresponding domain for the CNAME)
- 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
mbdvg
Updated on June 05, 2022Comments
-
mbdvg almost 2 years
I have a problem with domain hosting in Route 53.
I need to redirect from
xyz.com
towww.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 ofwww.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 almost 8 yearsIf 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 over 7 yearsWhen 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 over 7 yearsCorrect, but this is a reasonable solution.
-
netpoetica about 6 yearsCan you keep your files in the naked bucket and then redirect to www?
-
Gary Vernon Grubb over 5 yearsThis worked for me. I am using it with cloud front. Thanks.
-
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.