0

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?

jshawl
  • 297
  • 2
  • 13

1 Answers1

2

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.

Ansgar Wiechers
  • 4,247
  • 2
  • 18
  • 26