Best practice for placing DNS records and subdomains

Solution 1:

Generally the best practice, for ease of maintenance, would be something like this:

[A]     mydomain.com            123.45.67.89
[CNAME] www.mydomain.com        mydomain.com
[CNAME] blog.mydomain.com       mydomain.com
[CNAME] www.blog.mydomain.com   mydomain.com
[A]     mail.mydomain.com       123.45.67.89
[MX]    mydomain.com            mail.mydomain.com

This lets you change your A record for mydomain.com without disrupting your mail record or having to change each subdomain by hand.

You'll also need to set up your webserver to answer on those names. Here's an example of doing so in Apache:

NameVirtualHost 123.45.67.89:80
<VirtualHost 123.45.67.89:80>
    DocumentRoot /var/www/html/mydomain.com
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ErrorLog logs/mydomain.com-error_log
    CustomLog logs/mydomain.com-access_log combined
</VirtualHost>

<VirtualHost 123.45.67.89:80>
    DocumentRoot /var/www/html/blog.mydomain.com
    ServerName blog.mydomain.com
    ServerAlias www.blog.mydomain.com
    ErrorLog logs/blog.mydomain.com-error_log
    CustomLog logs/blog.mydomain.com-access_log common
</VirtualHost>

For the redirects you mentioned:

Question is, is this a common practice? Or are there better ways to do this? What I want to achieve is (user access -> redirect to):

mydomain.com          -> mydomain.com
www.mydomain.com      -> mydomain.com
blog.mydomain.com     -> blog.mydomain.com
www.blog.mydomain.com -> blog.mydomain.com
other.mydomain.com    -> error

To actually change the URL that's displayed in a client's address bar, that would need to be done on server side with mod_rewrite, and is not a function of DNS.

Solution 2:

Option B. Use CNAME records to specify aliases for existing A records. Same applies to the blog & www.blog entries. Choosing the CNAME record allows you to change the actually IP in one location (the A record). If you make all entries as A records you would need to update each individually.