Which DNS record should I use to redirect request to sub domain to main domain?
Solution 1
You can add a CNAME, but it would not suffice.
This way you only tell browsers that the IP of your blog is the same as the one pointed by your domain DNS record:
blog.dom.tld -> dom.tld -> <your.ip>
If your HTTP server does not implements Vhosts (and I suppose it does as you are in a shared server :), you would had done.
As your server is a Vhost, you have to instruct it to properly handle both blog.dom.tld and dom.tld as the same vhost. You can achieve this behavior using ServerAlias
apache directive, for example
EDIT:
don't know your host, but from their forum it seems you can login and do it by hand.
Solution 2
as already said, dns do not do redirection.
dns only resolving name to ip.
if you're using apache server, just point the domain to your server ip and you can use .htaccess for redirection.
Solution 3
DNS doesn't really do redirection like this. Usually you have to point both domains at a web server setup virtual hosts for both domains, and create a rule in in the virtual host to send a redirect.
If you look around there are free/cheap services (e.g. dyndns) that will do the redirection for you. Basically you point the name that you want redirected at them, then tell them what URL to redirect too.
Related videos on Youtube
![Xinus](https://i.stack.imgur.com/rshgn.jpg?s=256&g=1)
Xinus
I am a software developer, you can know more about me on my blog https://spsarolkar.github.io/
Updated on September 17, 2022Comments
-
Xinus almost 2 years
I created a DNS record in co.cc to make it point to x10hosting account. So I have like
<mydomain>.co.cc - A - <x10 ip>
Its working properly. Now problem is I have already mentioned name like
blog.<mydomain>.co.cc
in my previous resumes which I cannot change. So is it possible to redirect sub-domain request to main domain using DNS record. -
Sandokas over 14 yearsmy answer explains why, and how you can do it work
-
Xinus over 14 yearsWhere can I make those settings , I have control panel 11 on x10hosting.com
-
Jaykul over 14 yearsYou need to add a subdomain on the control panel, if they'll let you do that.
-
Xinus over 14 yearsThanks.. it worked :) ... But why www was working using CNAME record? OR is it by default provided by x10hosting ?
-
Sandokas over 14 yearsI suppose the default env of x10 already handle in the same vhost both domain and www.domain, as it is quite usual that the are the same :)
-
Atulmaharaj over 14 yearsCorrect. Mod_rewrite in your Apache config or .htaccess will allow very powerful redirection and URL rewriting.
-
bortzmeyer about 14 years-1 because adding the CNAME has side-effects (aliasing blog.mydomain.example to mydomain.example: that will inherit MX, NS etc records). Good practice is to add address records (A and AAAA).
-
Sandokas about 14 yearsSide effects that are normal.. if they are really the same it is obvious they should have the same MX and so on .. an alias is a "link" to something, not a "fake" or "ghost" of a real think. I do not agree, sorry.