Apache can do name-based matching.
For example, in my
httpd.conf, I have the following snippets:
Listen 192.168.0.30:80\nBindAddress myname.com\nBindAddress www.myname.com\nBindAddress wine.myname.com\n\n[...]\n\n####################\n# www.myname.com\n####################\n<VirtualHost *>\n ServerName www.myname.com\n ServerAdmin webmaster@myname.com\n DocumentRoot /var/vhosts/myname\n ScriptAlias /cgi-bin/ /var/vhosts/myname/cgi-bin/\n ErrorLog /var/log/apache/myname-error.log\n CustomLog /var/log/apache/myname-access.log common\n CustomLog /var/log/apache/myname-agent.log agent\n</VirtualHost>\n\n####################\n# wine.myname.com\n####################\n<VirtualHost *>\n ServerName wine.myname.com\n ServerAdmin webmaster@myname.com\n DocumentRoot /var/vhosts/wine\n ScriptAlias /cgi-bin/ /var/vhosts/wine/cgi-bin/\n ErrorLog /var/log/apache/wine-error.log\n CustomLog /var/log/apache/wine-access.log common\n</VirtualHost>
Note that I have changed any kind of essential information, and so may have introduced some minor typos. However, that's basically the gist of how you'd do it.
If you go to [link|http://myname.com/|http://myname.com/] or [link|http://www.myname.com/|http://www.myname.com/], you will get the same site (configuration information for plain old "myname.com" not shown above, but is the same as for "www.myname.com".) If you go to [link|http://wine.myname.com/|http://wine.myname.com/], you will get a login screen for my wine database application that I set up a couple years back and have sorely neglected since then.
Yes, yes, I know that you weren't looking for actual code to do it, but it was actually at my fingertips since I was just hackin' around in there earlier.