Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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
add comment

2 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.

share|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
    
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 4 '09 at 9: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 4 '09 at 10:14
2  
The '@' just means "the current $ORIGIN" - i.e. it's a short hand for "this domain" –  Alnitak Dec 4 '09 at 11:42
show 2 more comments

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
share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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