Digital strategist, front end + email developer, WordPress enthusiast, IT tinkerer, and not-so-horrible writer

Static Subdomains With WordPress Multisite Wildcard Subdomains

Best of Both Worlds: Static Subdomains With WordPress Multisite Wildcard Subdomains

Scenario: Let's say you have a few existing non-WordPress sites that are hosted in subdomains alongside a WordPress site hosted on the root. Not an entirely alien scenario, I have a couple domains with a similar setup. In my case the subdomains house utility software and one-off solutions that need to be hosted.

Now imagine that you want to extend your WordPress ecosystem and turn your existing domain into a multisite install. With that, you'll need a DNS wildcard entry and a tweak to apache's configuration file, httpd.conf. Easy, right? It may not be, depending on how your httpd.conf file is currently configured.

The solution is to rejigger httpd.conf, to place the wildcard entry last. As it turns out Apache reads its configuration file linearly, from start to end.

When I started in on this tonight, my configuration file looked something like this:

<VirtualHost 192.168.0.1:80 >
ServerName *.anseltaft.com
ServerAlias *.anseltaft.com anseltaft.com
DocumentRoot /home/path/domains/anseltaft.com/public_html
CustomLog /tmp/log/www/domains/anseltaft.com.bytes bytes
CustomLog /tmp/log/www/domains/anseltaft.com.log combined
ErrorLog /tmp/log/www/domains/anseltaft.com.error.log
</VirtualHost>
<VirtualHost 192.168.0.1:80 >
ServerName yomomma.anseltaft.com
ServerAlias yomomma.anseltaft.com
DocumentRoot /home/path/domains/anseltaft.com/public_html/yomomma
CustomLog /tmp/log/www/domains/anseltaft.com.yomomma.bytes bytes
CustomLog /tmp/log/www/domains/anseltaft.com.yomomma.log combined
ErrorLog /tmp/log/www/domains/anseltaft.com.yomomma.error.log
</VirtualHost>
<VirtualHost 192.168.0.1:80 >
ServerName chewbacca.anseltaft.com
ServerAlias chewbacca.anseltaft.com
DocumentRoot /home/path/domains/anseltaft.com/public_html/chewbacca
CustomLog /tmp/log/www/domains/anseltaft.com.chewbacca.bytes bytes
CustomLog /tmp/log/www/domains/anseltaft.com.chewbacca.log combined
ErrorLog /tmp/log/www/domains/anseltaft.com.chewbacca.error.log
</VirtualHost>

By the time I finished reading this ServerFault.com post, the working solution looked something like what is below, with a wilcard entry at the end.

<VirtualHost 192.168.0.1:80 >
ServerName yomomma.anseltaft.com
 ServerAlias yomomma.anseltaft.com
 DocumentRoot /home/path/domains/anseltaft.com/public_html/yomomma
CustomLog /tmp/log/www/domains/anseltaft.com.yomomma.bytes bytes
 CustomLog /tmp/log/www/domains/anseltaft.com.yomomma.log combined
 ErrorLog /tmp/log/www/domains/anseltaft.com.yomomma.error.log
</VirtualHost>
<VirtualHost 192.168.0.1:80 >
ServerName chewbacca.anseltaft.com
 ServerAlias chewbacca.anseltaft.com
 DocumentRoot /home/path/domains/anseltaft.com/public_html/chewbacca
CustomLog /tmp/log/www/domains/anseltaft.com.chewbacca.bytes bytes
 CustomLog /tmp/log/www/domains/anseltaft.com.chewbacca.log combined
 ErrorLog /tmp/log/www/domains/anseltaft.com.chewbacca.error.log
</VirtualHost>
<VirtualHost 192.168.0.1:80 >
ServerName *.anseltaft.com
 ServerAlias *.anseltaft.com anseltaft.com
 DocumentRoot /home/path/domains/anseltaft.com/public_html
CustomLog /tmp/log/www/domains/anseltaft.com.bytes bytes
 CustomLog /tmp/log/www/domains/anseltaft.com.log combined
 ErrorLog /tmp/log/www/domains/anseltaft.com.error.log
</VirtualHost>

To close the loop, you'll need to restart the Apache service and viola! A webserver setup that gives you the best of both worlds: static subdomain sites running alongside a potential infinite number of WordPress multisites. Will you be able to do this yourself? Perhaps. It depends how adept you are at editing your httpd.conf file.

Leave a reply