Is there any way in which I can set an Apache virtual host to match a partial domain via a wildcard?
For example, we're using xip.io to power some vhosts in our development environment, with our standard development domain looking something like domain.com.127.0.0.1.xip.io
, which means we can use a vhost that looks something like this:
<VirtualHost *:80>
DocumentRoot "/srv/www/domain.com/public_html"
ServerName domain.com.127.0.0.1.xip.io
ServerAlias www.domain.com.127.0.0.1.xip.io
<Directory "/srv/www/domain.com/public_html">
Options +Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "/srv/www/domain.com/log/error.log"
CustomLog "/srv/www/domain.com/log/access.log" common
LogLevel error
</VirtualHost>
This is fine, until the IP address has to change. There could be many reasons why the IP has to change (such as letting other people view your work, etc..) and in this world of dynamic IPs (which is why something like xip.io is so helpful), being able to adapt to this change, without having to faffabout with the vhost settings, would be helpful.
With this in mind, is it possible to set-up the ServerName
and ServerAlias
settings above to support wildcards? So that rather than having to set-up an alias for every possible IP address which might resove to this machine, it instead looks something like this?
<VirtualHost *:80>
DocumentRoot "/srv/www/domain.com/public_html"
ServerName domain.com.*.xip.io
ServerAlias www.domain.com.*.xip.io
<Directory "/srv/www/domain.com/public_html">
Options +Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "/srv/www/domain.com/log/error.log"
CustomLog "/srv/www/domain.com/log/access.log" common
LogLevel error
</VirtualHost>
Thank you.