user1105192
user1105192

Reputation: 412

DNS www & non-www + is it ok to have 2 A Records

I wanted to ask if its ok to have 2 A Records for www and non-www (on the same IP address) and then direct non-www to www on Apache?

Or should this be 1 A Record and use a CNAME to redirect?

Or a different preferred solution?

Upvotes: 2

Views: 4082

Answers (1)

Michael Krebs
Michael Krebs

Reputation: 1314

It is OK to point www.[mydomain].com and [mydomain].com to the same IP address, by using an A record for each of them. Replace [mydomain] with your domain name of course.

You can use CNAMEs to allow one domain name to automatically get the DNS records of another domain name, but it can be tricky, and there are some unexepected restrictions. For example, you can't use a CNAME at the root of your zone file. In practical terms, you can use a CNAME to point ftp.[mydomain].com to the same IP address as www.[mydomain].com, but you can't define [mydomain].com using a CNAME. CNAMEs can't coexist with other records with the same domain name, and there are other records you'll need to have for [mydomain].com, like NS records, and SOA record, and if you want email, an MX record -- all of which would conflict with a CNAME. My advice, avoid CNAMEs -- they are complicated, hard to get right, and of very limited use.

One nice solution is to give each of these 2 domain names the same IP address in each of the A records, and then tell the web server to redirect [mydomain].com to www.[mydomain].com using what is known as a "301 redirect". You can put this in the .htaccess file for [mydomain].com:

Redirect 301 / http://www.[mydomain].com/

Upvotes: 1

Related Questions