2

I want example.com and *.example.com to always resolve to www.example.com

So if I set the DNS records as:

www      A          server ip
(root)   CNAME      www.example.com 
*        CNAME      www.example.com

Would these be the correct settings to achieve this?

If so, could there be any search engine problems? I don't want any search bots to think I'm serving different subdomains with the same content, or something like that.

thanks!

Spoonface
  • 207
  • 3
  • 8
  • If what you want is for web users to always see URLs starting with `www.example.com`, you need to do this at the HTTP level, not DNS. For example use an Apache `RewriteMatch` to send back a redirect to www whenever someone requests a resource from plain example.com. – poolie Nov 23 '10 at 05:39

2 Answers2

8

No, this doesn't work.

You can't legally have a CNAME at the root of your zone, because the SOA record belongs there too and it's not possible to have both a CNAME and other RRs attached to the same domain name.

Your zone file would need to look like this:

$ORIGIN example.com.
@       IN SOA ......
        IN A <server_ip>
*       IN A <server_ip>

There's no explicit need for a specific www record in this case, because the wildcard covers that.

Alnitak
  • 21,191
  • 3
  • 52
  • 82
  • Ok then, not sure I follow completely (what does the @ symbol signify?) but would this be right? (root) A server ip * A server ip Would search engines be happy with that? Also I still want www.example.com to be visible in the address bar (even if they entered example.com), would that have to some server side setting or something else? thanks! – Spoonface Dec 04 '09 at 09:24
  • drat the formatting wasnt used.. i'll put the comment below – Spoonface Dec 04 '09 at 09:25
  • 2
    The '@' just means "the current $ORIGIN" - i.e. it's a short hand for "this domain" – Alnitak Dec 04 '09 at 11:42
  • Not sure I follow completely (what does the @ symbol signify?) but would this be right? (root) A server ip * A server ip Would search engines be happy with that? Also I still want www.example.com to be visible in the address bar (even if they entered example.com), would that have to be a server side setting or something else? thanks! – Spoonface Dec 04 '09 at 09:25
  • You need to add www as another A record and setup a redirect in the webserver from example.com to www.example.com. – Sim Dec 04 '09 at 10:14
  • Search engines will be fine with it. Sim's comment isn't quite right, though. If you want the address bar to end up as 'www.example.com' even though the user only typed 'example.com' then you do need the webserver to do a redirect. You _don't_ however need an explicit 'www' record, the wildcard will work fine. – Alnitak Dec 04 '09 at 11:46
1

It has been a while since I had to do this but I don't think you can't mix CNAME records with other records.

See DNS wildcard RRs of different type possible?

So it would be better as:

www      A          server ip
(root)   A          server ip 
*        A          server ip

or

www      CNAME      server.example.com
server   A          server ip
(root)   A          server ip 
*        A          server ip
Sim
  • 1,858
  • 2
  • 17
  • 17