RRSet of type CNAME with DNS name foo.com. is not permitted at apex in zone bar.com
Solution 1:
As per RFC1912 section 2.4:
A CNAME record is not allowed to coexist with any other data. In
other words, if suzy.podunk.xx is an alias for sue.podunk.xx, you
can't also have an MX record for suzy.podunk.edu, or an A record, or
even a TXT record. Especially do not try to combine CNAMEs and NS
records like this!:
podunk.xx. IN NS ns1
IN NS ns2
IN CNAME mary
mary IN A
The RFC makes perfect sense as the nameserver wouldn't know whether it needs to follow the CNAME or answer with the actual record the CNAME overlaps with. bar.com
is a zone therefore it implicitly has an SOA record for the bar.com
name. You can't have both a SOA record and a CNAME with the same name.
However, given that SOA records are generally used only for zone maintenance, these situations where you want to provide a CNAME at the zone's apex are quite common. Even though the RFC prohibits it, many engineers would like a behaviour such as: "follow the CNAME unless the query explicitly asks for the SOA record". That's why Route 53 provides alias records
. These are a Route 53 specific feature which offer the exact functionality you require. Have a look at http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingAliasRRSets.html
Solution 2:
- Create an S3 Bucket called
bar.com
. (The name must be the same as the domain you want to redirect from in order for this to work!) - In the
bar.com
S3 Bucket go toProperties
>Static Website Hosting
, selectRedirect all requests to another host name
and enterfoo.com
in the text box. - Back in Route 53, in your
Hosted Zone
forbar.com
, clickCreate Record Set
. SelectA - IPv4 address
for type. ClickYes
forAlias
. Click the text box forAlias Target
.bar.com
should be listed under-- S3 Website Endpoints --
. Save the record. Wait a few minutes and you should have a redirect setup to redirect requests from bar.com to foo.com.
You can use this same method to redirect a naked domain to a subdomain (like www). I use this in cases where www.foo.com has to be a CNAME so I redirect from foo.com to www.foo.com with this same method. If foo.com is an A record, you can use this technique to redirect from www.foo.com to foo.com.
NOTE: this method will forward with the full path. i.e. http://bar.com/test will forward to http://foo.com/test.