Question

So I have a Virtual Host set up and I snagged this as my Document Root

VirtualDocumentRoot "/sites/%1+/www"

Everything works great but this one thing has been killing me. Does anyone have any idea what %1+ means? Could someone breakdown exactly what it is and how it works. I understand it is pointing the server to where to look but what is %1+ doing?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top