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!

link|improve this question

80% accept rate
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 5:39
feedback

3 Answers

up vote 8 down vote accepted

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.

link|improve this answer
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 4 '09 at 9:24
drat the formatting wasnt used.. i'll put the comment below – Spoonface Dec 4 '09 at 9:25
2  
The '@' just means "the current $ORIGIN" - i.e. it's a short hand for "this domain" – Alnitak Dec 4 '09 at 11:42
feedback

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
link|improve this answer
-1 for the second example which is complete incorrect - you can't put a hostname in an A record. – Alnitak Dec 4 '09 at 8:53
Yeah that was meant to be a CNAME not an A record. Fixed now. – Sim Dec 4 '09 at 9:15
feedback

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!

link|improve this answer
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 4 '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 4 '09 at 11:46
ok then thanks ;-) – Spoonface Dec 4 '09 at 14:11
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.