Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have an apache2 installation on www.main_domain.com (invalid underscore in domain name is intentional; this is an example), and the default page gives links for two secondary sites, also served by the same webserver since they point to the same address. The sites have lots of stuff in common, so I wouldn't want to do things using symbolic/hard links.

What I would like to do is:

  • if the client requests www.main_domain.com, I'd like to serve the current /var/www/index.html start page. That page contains links to secsite1.html and secsite2.html (the start pages for the secondary sites).
  • if the client requests www.secondary_site_1.com, I'd like to serve the /var/www/secsite1.html start page.
  • likewise for www.secondary_site_2.com: serve /var/www/secsite2.html as a first page.

Note that I want to change only the start page; otherwise, any page/image/file should be interchangeably accessible using the same path under each domain name.

Please let me know if I need to clarify more.

share|improve this question
    
You're gonna suffer a lot of duplicate content penalty if you create 3 identical sites that only differ in their homepages. Also, your use of "subdomain" is confusing. That's not what most people mean when they refer to a subdomain. You should just refer to them as "subsites" or "secondary domains". –  Lèse majesté Dec 28 '11 at 8:53
    
@Lèsemajesté: you're right about the term “subdomain” being confusing. Thanks. –  tzot Dec 28 '11 at 9:20
add comment

2 Answers

up vote 2 down vote accepted

I can't think of any reason why one would want this sort of setup, but to make the best of a bad situation, I would give the sites different docroots to avoid unnecessary duplication of content/URLs and make the sites more maintainable, e.g.:

/var/www/site1
/var/www/site2
/var/www/site3

To share assets, you ought to just keep the assets in the main site's docroot and use mod_rewrite to 301 redirect from the other domains. This will allow you to use a single folder to keep shared assets, prevent duplicate URLs, and allow visitors to share cached files between sites.

In case you want to give a specific site its own version of a particular file, you just need to upload it to the respective path in its docroot, and visitors to that domain will see that version while still sharing all other assets.

share|improve this answer
    
Thank you for your answer. –  tzot Dec 30 '11 at 11:13
add comment

You could use a scripting language to detect the url that was entered and have the index page (index.php for example) load index.html, subdomain1.html or subdomain2.html based on the sub-domain detected. For Example index.php would be:

<?php
if($_SERVER['HTTP_HOST'] == 'www.sub_domain_1.com') { include('subdomain1.html'); }
else if($_SERVER['HTTP_HOST'] == 'www.sub_domain_2.com') { include('subdomain2.html'); }
else { include('index.html'); }
?>
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.