Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
                                                              #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.

share|improve this question
    
Have you tried the [C] (chain) flag? –  Dennis Williamson Jan 2 '11 at 7:32

1 Answer 1

up vote 0 down vote accepted

No, only the rule that immediately follows one or more RewriteCond directives is included. That is:

                                                          #www.   domain .   tld
RewriteCond     %{HTTP_HOST}                                (?:.*\.)?([^.]+)\.(?:[^.]+)$
RewriteCond     /home/%1/                                   -d
# This will only be run if the two conditions above, are met
RewriteRule     ^(.+)                                       %{HTTP_HOST}$1

# These will always be run!
RewriteRule     (?:.*\.)?([^.]+)\.(?:[^.]+)/media/(.*)$    /home/$1/client/media/$2 [L] 
RewriteRule     (?:.*\.)?([^.]+)\.(?:[^.]+)/(.*)$          /home/$1/www/$2 [L] 

If you notice in your log, it skips the first RewriteRule, but doesn't even check conditions for the other two.

share|improve this answer
    
Arggg. Why don't they come up with a simple if/else normal language for this type of thing. –  ParoX Jan 2 '11 at 6:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.