#www. domain . tld
RewriteCond %{HTTP_HOST} (?:.*\.)?([^.]+)\.(?:[^.]+)$
RewriteCond /home/%1/ -d
RewriteRule ^(.+) %{HTTP_HOST}$1
RewriteRule (?:.*\.)?([^.]+)\.(?:[^.]+)/media/(.*)$ /home/$1/client/media/$2 [L]
RewriteRule (?:.*\.)?([^.]+)\.(?:[^.]+)/(.*)$ /home/$1/www/$2 [L]
Here is rewritelog output:
#(4) RewriteCond: input='tfnoo.mydomain.org' pattern='(?:.*\.)?([^.]+)\.(?:[^.]+)$' [NC] => matched
#(4) RewriteCond: input='/home/mydomain/' pattern='-d'
=> not-matched
#(3) applying pattern '(?:.*\.)?([^.]+)\.(?:[^.]+)/media/(.*)$' to uri 'http://www.mydomain.org/files/images/logo.png'
#(3) applying pattern '(?:.*\.)?([^.]+)\.(?:[^.]+)/(.*)$' to uri 'http://www.mydomain.org/files/images/logo.png'
#(2) rewrite 'http://www.mydomain.org/files/images/logo.png'
-> '/home/mydomain/www/logo.png'
If you note on the 2nd 4 it failed the -d (if directory exists) pattern. Which is correct. mydomain does not have a /home/. Therefore it should never rewrite, atleast according to my understanding that all rewriterules are subject to rewriteconds as logical ANDs.