This can be done if you follow the instructions for Simple dynamic virtual hosts in the Apache documentation.
Follow a standard convention for your VirtualHosts, like
/var/www/www.subdomain.org/cgi-bin, and then add something like the following to your HTTP configuration.
Note how the paths below use
%0. This will be populated by the server name which is used in the contents of the
Host: header in the HTTP request. You must use
UseCanonicalName Off for this to work. Also note that if a visitors goes to 'www.example.com' 'example.com', the 'Host: ' is different, therefore '%0' is different, so you'll need symlinks or another method to tell Apache that
/var/www/example.com/ are the same thing.
# get the server name from the Host: header
# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon
# include the server name in the filenames used to satisfy requests