I'm not knowledgeable at all about C-NAMES
, A-RECORDS
, name servers and the like, so just bear with me on this one:
I want to redirect subdomain.example.org to another domain somethingelse.com. I do own both domains and both domains run on shared hosting. When creating a subdomain, all I can do out-of-the-box is do a HTTP redirect (302, yuck!) or a frame redirect.
I also can set the DNS records on one host like nameserver, CNAME
- but I would have know clue what I am doing.
Please explain to me how routing with nameservers works and how I should (even if not possible with my current host) redirect subdomain.example.org to somethingelse.com with the user-visible URL staying at "subdomain.example.org"
Name servers do not route anything. Name servers respond to requests for names, and they eventually returns an IP. CNAME records return a name, which is then looked up to get the IP. The only thing you really can do with your DNS records is make sure that your name is set returns the IP address of a server that will accept the traffic and do what you want.
If you setup the web server with name-based virtual hosting setup, and the main name for that virtual host is
somethingelse.com
then you could set an additional name for that virtual hostsubdomain.example.org
. In DNS you set the records to return the IP of the virtual host servingsomethingelse.com
.The web site hosted on
somethingelse.com
must used relative links wherever possibly or the user will quickly realize that they are now have been switched to a different domain.Just create an A record that associates a name with an IP, or CNAME record that points to an A record that points at the IP you want.
DNS knows nothing. What you are asking for needs to be handled on the HTTP server.
You can point a DNS record at any IP address you like. In the case of HTTP, part of the request includes the host name you are trying to access. The Google web servers may choose to reject based on the hostname that is part of the HTTP request.
Setting up a DNS name to point at Google's servers is even supported if you are a Google Apps customer. There is a procedure you most follow to tell Google what name you will be using for a particular page. Google then adjusts their configuration accordingly.
If you are using some other protocol that doesn't include the hostname used to access then the server would have no way of knowing what is what. You can easily test this for yourself by creating a record like
googledns.example.org IN A 8.8.8.8
, and then runningping googledns.example.org
, Google's DNS server will respond to the ping. The name you used to for the ping command is not included in an ICMP echo reply at all, only the IP address.Why can't you just setup a .htaccess file (with a 301 redirect) in the folder that the subdmain is in.
For Example:
Edit that new .htaccess file and add the following code
Redirect 301 / http://somethingelse.com
With / being the root directory of your subdomain, and http://somethingelse.com being where you want it sent.
Works for me.
DNS redirects using CNAMES won't work the way you want them to on a shared host.
For our purposes, suppose you have a 'CNAME' record for subdomain.example.org that point to somethingelse.com and an 'A' record for somethingelse.com. When you visit subdomain.example.com, a DNS server is first queried to determine the correct IP address. The DNS server will see the CNAME record and recursively determine the IP address for somethingelse.com, which is then returned to your desktop.
Your browser will then contact that IP address, it it will ask for subdomain.example.com. In fact, it doesn't even know somethingelse.com exists.
If you had a dedicated box, you could get CNAMEs to work like you think they should, but you would forfeit the ability to use a name-based virtual host. With IP-based vhosts, any domain that points to a given IP will serve the same content.
To get your browser's address bar to say subdomain.example.org while the page is being served from somethingelse.com, you may reconsider using the frame redirect provided by your host.
Another possibility, if your host provides mod_proxy, is to set up a reverse proxy in subdomain.example.com's virtualhost configuration:
This will cause subdomain.example.com to provide somethingelse.com's content while still reporting subdomain.example.com as the source domain.
The only complete solution is to setup a web server to listen for 'subdomain.example.org' and redirect it to 'somethingelse.com' with HTTP redirect.
If you use a cname to point 'subdomain.example.org' to 'somethingelse.com', the web browser will talk to the web server for 'somethingelse.com' but it will say "I'm looking for subdomain.example.org" which it may not be configured for. If you can configure the web server to accept both URLs, then cname will work fine.