RewriteRule applying pattern even though 1 of the RewriteCond's failed

Posted by BHare on Server Fault See other posts from Server Fault or by BHare
Published on 2011-01-02T04:02:14Z Indexed on 2011/01/02 4:55 UTC
Read the original article Hit count: 274

                                                              #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.

© Server Fault or respective owner

Related posts about apache

Related posts about mod-rewrite