Read the documentation: http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
All the directives in this module interpolate a string into a pathname. The interpolated string [...] may be either the server name [...] or the IP address of the virtual host on the server in dotted-quad format. The interpolation is controlled by specifiers inspired by printf which have a number of formats:
[...] %N.M insert (part of) the name
N and M are used to specify substrings of the name. N selects from the dot-separated components of the name, and M selects characters within whatever N has selected. M is optional and defaults to zero if it isn't present; the dot must be present if and only if M is present. The interpretation is as follows:
0 the whole name 1 the first part [...] 2+ the second and all subsequent parts [...]
For a very large number of virtual hosts it is a good idea to arrange the files to reduce the size of the vhosts directory. To do this you might use the following in your configuration file:
UseCanonicalName Off VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2
A request for http://www.domain.example.com/directory/file.html will be satisfied by the file /usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html.
So, in
VirtualDocumentRoot "/sites/%1+/www"
the request
www.example.com
would resolve to
/sites/www.example.com/www