Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have a domain professionally hosted:

Example.net

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

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

For example: visiting bacon.home.example.net 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.

1 Answer 1

You need to enable mod_rewrite

a2enmod rewrite

and add a the following directives to your Apache configuration:

ServerAlias *.home.example.net

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

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 foo.home.example.net to an IP address without name resolution? –  Ansgar Wiechers Sep 2 '12 at 22:50
1  
If he's already mapping *.home.example.net 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.