Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With Mac OS X 10.6, I'm having some fun moving from the old way of hosting multiple sites (having a block of code in a .conf file for each virtual host) to a slightly less old way (telling the server to look in /sites/ for a folder named and serve whatever is in there.)

Making this happen only requires a couple things: in /etc/apache2/httpd.conf, uncomment this line

#Include /private/etc/apache2/extra/httpd-vhosts.conf

and below that add

VirtualDocumentRoot /sites/%0

Then, in


add a block of code that says

<Directory /sites>
 Order Deny,Allow
 Allow from all

My only problem is I can't find an easy way to serve the same content if the visitor requests or With the old way it's easy to make it respond to any subdomain. I'm sure there's a way to do this with the Apache config so I don't have to resort to making lots of symlinks in /sites/. I couldn't find an obvious answer at

Ideally, not only would I like to serve the same content with or without the 'www', I'd like to be able to still use subdomains as needed with different, so I'd rather not have everything (* serve from the same folder.

share|improve this question
I don't think it's possible unless you find a place to put ServerName mydomain.comand ServerAlias Maybe you could do it with a DNS redirect? – Bart De Vos Apr 11 '11 at 8:14
You definitely should use the solution proposed by TiZon (With ServerName and ServerAlias) and then use mod_rewrite to rewrite the non-preferred domain to the preferred one with 301. Otherwise google will treat your sites and incoming links as 2 different ones with duplicate content (unless you use the "canonical url" parameter) – shakalandy Apr 11 '11 at 8:59

You're going to have problems with cookies not crossing over between the sites if you have (effectively) 2 virtual hosts with the same document root. A better solution would be to redirect everything for a non www domain to the corresponding www domain. There are lots of different ways to do this, e.g. using a 404 handler in the (empty) default vhost or using mod_rewrite on %{SERVER_NAME}

share|improve this answer

Your Answer


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.