Upgrading to OSX Yosemite upgrades Apache to 2.4 which caused me a few issues with my dynamic host file. Here’s my updated vhost file which works for both single and multi-part domains.
My local development urls all end in .dev e.g. marclloyd.dev. The vhost below will forward marclloyd.dev to the folder /Library/WebServer/Projects/marclloyd. This will work for all domains ending in .dev .
<Virtualhost *:80>
VirtualDocumentRoot "/Library/WebServer/Projects/%1"
ServerName vhosts.dev
ServerAlias *.dev
UseCanonicalName Off
<Directory "/Library/WebServer/Projects/*">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</Virtualhost>
In my full time role as lead developer we use multi-part domains for local development e.g. the url for working on this site locally would something like marclloyd.website.marc.thecompany.co.uk. The code below will forward all domains ending with .marc.thecompany.co.uk to a folder named using the first 2 parts of the domain. e.g. marclloyd.website.marc.thecompany.co.uk will forward to /Library/WebServer/Projects/marclloyd.website
<Virtualhost *:80>
VirtualDocumentRoot "/Library/WebServer/Projects/%1.0.%2.0
ServerName vhosts.marc.thecompany.co.uk
ServerAlias *.marc.thecompany.co.uk
UseCanonicalName Off
<Directory "/Library/WebServer/Projects/*">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</Virtualhost>
Here’s my full httpd-vhosts.conf file:
Listen 80
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Projects"
ServerName localhost
</VirtualHost>
<Virtualhost *:80>
VirtualDocumentRoot "/Library/WebServer/Projects/%1.0.%2.0
ServerName vhosts.marc.thecompany.co.uk
ServerAlias *.marc.thecompany.co.uk
UseCanonicalName Off
<Directory "/Library/WebServer/Projects/*">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Library/WebServer/Projects/%1"
ServerName vhosts.dev
ServerAlias *.dev
UseCanonicalName Off
<Directory "/Library/WebServer/Projects/*">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</Virtualhost>