Last Updated: September 09, 2019
·
1.041K
· tamasd

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+
</VirtualHost>

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.127.0.0.1.xip.io then apache will match it to /Users/<username>/Sites/foo.bar.