As someone who spends most of the day testing and developing eZ Publish, I always have multiple instances of eZ Publish checked out. Different versions, customer installations, etc. Previously I’ve created a new virtual host in Apache for each installation — very painful indeed.
I went searching for a better solution — one that wouldn’t need
reconfiguring of Apache. I could have used rewrite rules to map part of the URL to a directory, however rewrite rules will get messy
fast. I want my configuration to be as clean and simple as possible. Some
researching later and I stumbled upon the
directive. From the VirtualDocumentRoot documentation:
The VirtualDocumentRoot directive allows you to determine where Apache will find your documents based on the value of the server name. The result of expanding interpolated-directory is used as the root of the document tree in a similar manner to the DocumentRoot directive’s argument.
Sounds perfect. Here’s my new and improved virtual host configuration I came up
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
How it works
This is the same virtual host setup as explained in the eZ Publish installation documentation, except for 2 new directives.
DocumentRoot, we use
VirtualDocumentRootto dynamically set the document root depending on the Host HTTP header. The
%1specifies that we only want the first part of the host name. For more information about
VirtualDocumentRoot, check out the mod_vhost_alias documentation.
RewriteRule .* /index.php [PT]
[PT](pass through to next handler) was added to make sure the document root is set using
VirtualDocumentRoot. If omitted the default
DocumentRootsetting will be used, resulting in paths looking like /www/index.php, instead of /www/trunk/index.php.
To illustrate how the mapping between the host header and directories on your file system, here are some examples: