Which DNS record should I use to redirect request to sub domain to main domain?

6,582

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.

Share:
6,582

Related videos on Youtube

Xinus
Author by

Xinus

I am a software developer, you can know more about me on my blog https://spsarolkar.github.io/

Updated on September 17, 2022

Comments

  • Xinus
    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
    Sandokas over 14 years
    my answer explains why, and how you can do it work
  • Xinus
    Xinus over 14 years
    Where can I make those settings , I have control panel 11 on x10hosting.com
  • Jaykul
    Jaykul over 14 years
    You need to add a subdomain on the control panel, if they'll let you do that.
  • Xinus
    Xinus over 14 years
    Thanks.. it worked :) ... But why www was working using CNAME record? OR is it by default provided by x10hosting ?
  • Sandokas
    Sandokas over 14 years
    I 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
    Atulmaharaj over 14 years
    Correct. Mod_rewrite in your Apache config or .htaccess will allow very powerful redirection and URL rewriting.
  • bortzmeyer
    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
    Sandokas about 14 years
    Side 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.