Apache Wildcard Virtual Hosts

Having a wildcard virtual hosting setup can be VERY useful for development environments. Let's look at how to set that up.

Overall, its a fairly simple setup. Just replace "example.com" with your chosen TLD and the rest will be handled for you. Apache will match the subdomain passed to the domain (E.G. blog.joshuabedford.com) and render the folder with the same name (E.G. /var/www/blog).


UseCanonicalName Off
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName example.com
	ServerAlias *.example.com
	VirtualDocumentRoot "/var/www/%1"
	<Directory ~ "/var/www/*">
	        Options Indexes FollowSymlinks MultiViews
	        AllowOverride All
	        Require all granted
	</Directory>
	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet