Last Updated: February 25, 2016
· yorirou

Apache dynamic vhosts with xip.io

If you want easily use subdirectories as subdomains on your localhost, the best way to do it with apache is using a dynamic vhost configuration with xip.io.

NameVirtualHost *:80
UseCanonicalName Off

<VirtualHost *:80>
  VirtualDocumentRoot /Users/<username>/Sites/%-7+

The only tricky part here is the %-7+ wildcard. This means that apache will ignore the last 6 parts of the domain name. So if you have foo.bar. then apache will match it to /Users/<username>/Sites/foo.bar.