# # Wildcard VirtualHost Example Using VirtualDocumentRoot # # Almost any Apache directive may go into a VirtualHost container. # This we know from the Apache documentation posted everywhere. # However, a hidden gem within that documentation is that we can use # regular expressions to match parts of the requested domain to paths # on our filesystem by using %1 and other variations. # # To use this, all we have to do is create cooresponding directories, # populate them with web content, and they're automatically served as long # as the URI we enter matches the regex scheme we have in our vhosts config. # This all works because of VirtualDocumentRoot /var/www/vhosts/%1/www # # /var/www/vhosts/testing/www/index.html -> http://testing.yourdomain.com # /var/www/vhosts/testing/www/info.php -> http://testing.yourdomain.com/info.php # /var/www/vhosts/foobar/www/index.html -> http://foobar.yourdomain.com # # Worth noting, I ONLY use this on dev environments. The code itself # is safe, but it opens the door for you being unaware of rogue # subdomains running under your site by simply creating a directory and # file in the right (or wrong, depending on outlook) place. # Options Indexes FollowSymLinks ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted # # Wildcard subdomains # ServerAlias *.yourdomain.com VirtualDocumentRoot /var/www/vhosts/%1/www