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

Here is my ideal setup that I would like to figure out how to do:

I have a domain professionally hosted:

I have a subdomain, that points to my Mac mini at home. I've already got this working just fine. The document root for is /Users/me/Sites

I want to setup dynamic subdomains such that anything that comes before (the regex version: * has the document root: /Users/me/Sites/$1

For example: visiting will have the doc root /Users/me/Sites/bacon

How can I get this setup so I don't have to add a new vhost for every project?

share|improve this question

closed as off topic by Sven, Magellan, HopelessN00b, MadHatter, mdpc Nov 8 '12 at 17:31

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

You need to enable mod_rewrite

a2enmod rewrite

and add a the following directives to your Apache configuration:

ServerAlias *

<Directory /User/me/Sites>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^home\.example\.net
  RewriteCond %{HTTP_HOST} ^([^.]+).home\.example\.net
  RewriteRule ^(.*)$$1 [L]

Of course you need to make sure that the DNS records and subdirectories for each subdomain exist.

share|improve this answer
Is there anyway to bypass "making sure the DNs record exists"? How does one do that? – jessh Sep 2 '12 at 22:42
Not unless you want to start managing hosts files. How is the browser supposed to resolve to an IP address without name resolution? – Ansgar Wiechers Sep 2 '12 at 22:50
If he's already mapping * to his localhost, that shouldn't matter – andy Sep 2 '12 at 23:03
You're right. I hadn't thought of wildcard DNS records. – Ansgar Wiechers Sep 2 '12 at 23:18
So just the mod rewrite will work then?! – jessh Sep 2 '12 at 23:48

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