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

I just registered a domain name (say http://www.abc.com ). I also have a website with content on it (say http://www.freehost.com/mywebsite).

I would like to redirect visitors that type http://www.abc.com to http://www.freehost.com/mywebsite. Can this be done with DNS records (and if so , how?)?

Thanks!!

Joel


Edit:

Thanks for all the answers! I understand that it works only for top level domains. What about subdomains? Can I use CNAME to redirect to http://mydomain.freehost.com ?

share|improve this question

migrated from stackoverflow.com Sep 21 '10 at 16:43

This question came from our site for professional and enthusiast programmers.

    

4 Answers 4

No, this can't be done with DNS records.

CNAME records can only redirect hostname to hostname, not hostname to full URL.

To do what you require you need a separate web server on www.abc.com which issues an HTTP redirect to send the user to the right URL. Note that your cheap web-host address will then also appear in the user's browser address bar.

Alternatively, if your web content is also available as http://subdomain.freehost.com/ then a CNAME to that is legal.

However the webserver will need to be configured to accept your new domain name (i.e. via the Host: header) and know which user's content to serve. Your free webhost may not permit that.

share|improve this answer

Two steps:

  1. You'll need to create a CNAME from www.abc.com to www.freehost.com.
  2. Create a redirect page (php, aspx, etc) at www.freehost.com to send anyone who hits it to www.freehost.com/mywebsite

You cannot fully implement your solution with DNS alone, but with the above steps you can achieve the result you are looking for.

share|improve this answer
    
It should probably be assumed that the OP cannot install content or redirections at the freehost's web root. –  Alnitak Sep 21 '10 at 15:07
    
Can I use CNAME to redirect to mydomain.freehost.com, i.e. subdomain –  Joel Sep 21 '10 at 15:15
1  
yes, that's legal. However the webserver will need to be configured to accept your new domain name (i.e. via the Host: header). Your free webhost may not permit that. –  Alnitak Sep 21 '10 at 15:20

Yes, subdomains are handled by DNS so you can set up a CNAME to point www.abc.com at mydomain.freehost.com (it's best not to call it a "redirect" - that's handled at the HTTP level, so it's potentially confusing).

Note though, that this still might not work correctly. It's probably best to set up a record in your drivers/etc/hosts file first and test that it works before you go about changing DNS records.

share|improve this answer

You really should be doing this via the htaccess file, not DNS. There are specific reasons you modify your CNAME records, a simple redirect is not one of them. Look here for a tutorial on htaccess, or google for one on your own.

EDIT: Also note that your web hosting provider will likely have an option in their control panel to do this for you if both domains have their DNS pointed to them.

share|improve this answer

Your Answer

 
discard

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