3

I have several sub-domains on 1 website

http://sub1.mysite.com
http://sub2.mysite.com
http://sub3.mysite.com

I've also registered equivalent domains for each of these sub-domains at

sub1.com
sub2.com
sub3.com

How can I set it so that when someone types the sub1.com domain, they see the content from http://sub1.mysite.com but still see sub1.com as the URL. So the content is really served from http://sub1.mysite.com without the visitors knowing that.

0

4 Answers 4

2

This is kind of multi-layered.

Firstly, you need to setup a CNAME record for sub1.com to point to sub1.domain.com. This is done via whoever is hosting the DNS for sub1.com. You should more than likely have a control panel at either your hosting company or your domain name registrar to add this.

All this does however is tell clients that your website sub1.com lives at a certain IP address (i.e. in the case of a CNAME, it says, look up the IP of sub1.domain.com and sub1.com lives at the same location.)

Secondly, you need to tell your webserver that sub1.com and sub1.domain.com are the same site.

For Apache, you probably already have a <VirtualHost> setup, so you would add in a ServerAlias directive to tell Apache that the VirtualHost also serves sub1.com as well as sub1.domain.com

... signifies that you have your own configuration directives in here already.

<VirtualHost ...>
    ServerName sub1.domain.com
    ServerAlias sub1.com
    ...
</VirtualHost>

Thirdly and lastly, you need to make sure that your site doesn't redirect or reference sub1.domain.com within the code (i.e. Header redirects through PHP, meta tag refreshes, or a href links within the HTML to redirect the user outside of the current domain).

Links should have absolute paths without the domain, e.g. 1 not 2

1.

<a href="/blah.html">Blah</a>

2.

<a href="http://sub1.domain.com/blah.html">Blah</a>
1

You need to have the domains point to the same server of the subdomains, and using your hosting control panel set the domains as aliases to the subdomain.

p.s. asking those questions on https://serverfault.com/ gives you much better feedback, since that is the place to ask such questions.

0

You will need to add a CNAME entry to your DNS zone. However you might need to adjust some login in your code if its dependent on requested host, cause your scripts will not see sub1.mysite.com but sub1.com, so adjust them accordingly to handle both cases.

-1

Sounds like you want a "Frame Redirect":

http://en.wikipedia.org/wiki/URL_redirection#Frame_redirects

3
  • This won't work for embedded images/css/js..
    – aularon
    Sep 7, 2010 at 0:56
  • Ugh, there are soooooo many better ways of doing this Sep 7, 2010 at 4:53
  • Fast, good, cheap. Pick two.
    – Rob Olmos
    Sep 7, 2010 at 5:00

You must log in to answer this question.