[selfnote] How to handle multiple domains with one apache vhost in a smart way

Today a customer asked for hosting several domains with different content on one apache virtual host. The little tricky part was, that the sites should not be accessed by subdirs like http://domain20.org/subdir20/ and http://domain21.org/subdir21/ which can be done with a little script which parses the $_SERVER['HTTP_HOST']. So mod_rewrite is an option.
To make it user accessible, we use .htaccess. This requires "AllowOverride +FileInfo" to be set for the DocumentRoot in the vhost config. The .htaccess in DocumentRoot could look something like:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain10.org$ [OR]
RewriteCond %{HTTP_HOST} domain11.org$
RewriteCond %{REQUEST_FILENAME} !dir1/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.) dir1/$1 [L]
RewriteCond %{HTTP_HOST} domain20.org$ [OR]
RewriteCond %{HTTP_HOST} domain21.org$
RewriteCond %{REQUEST_FILENAME} !dir2/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.
) dir2/$1 [L]