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.

I am rewriting php generated thumbnails with igly urls into nice ones. instead of img.php?src=bla.jpg&w=200&h=100 the static filenames IMG-file_w200_h100.jpg

Because the rewrite is so complex and involves many variations, only urls starting with IMG- should be listening to the rewrite rule. The conditional first rule however doesnt seem to work: if i change it into IMF or something else, it still fires the rewrite rules! Any ideas as to why the conditional doesnt work?

# Rewrite imgcpu?src= thumbnail maker to nice static urls
RewriteCond %{REQUEST_URI} ^IMG.*$
RewriteRule ^IMG-(.+)_w(.+)_h(.+)_f(.+).jpg$ imgcpu\?src=$1\.jpg&w=$2&h=$3&f=$4 [L]
RewriteRule ^IMG-(.+)_w(.+)_q(.+).jpg$ imgcpu\?src=$1\.jpg&w=$2&q=$3 [L]
etc
share|improve this question
2  
Because it's lazy! Nyuk nyuk nyuk. –  mfinni Dec 15 '10 at 19:14
add comment

2 Answers

up vote 1 down vote accepted

The RewriteCond is actually processed after the RewriteRule matches! Here's a diagram from the Apache docs:

Rewrite Control Flow

share|improve this answer
    
Thanks Dennis for the graph. So, if i understand correctly, there is no speed gain? it will check every single REwriteRule anywayz? –  Sam Dec 15 '10 at 21:33
1  
@Sam: No speed gain. If RewriteRules are [C] chained it won't go through all of them, though, it stops processing that group on the first failed match. RewriteCond is just for selecting whether a matching RewriteRule is applied. It's like short-circuit processing of if (RW and RC) then ... where the "RC" is only evaluated if the "RW" is true. –  Dennis Williamson Dec 15 '10 at 23:05
    
Hi Dennis, interesting. I see, its just another Does the entire chain group of rules apply to each of the files ( in this case images ) that want to be rewritten, right? I did apply [C] on all except last rule with the unelegant reqritecode above but failed. should it be [C,L] or sometin else? –  Sam Dec 16 '10 at 4:09
1  
@Sam: Have you tried using RewriteLog rewrite_log and RewriteLogLevel 9 and looking at the log so you can see what's happening? –  Dennis Williamson Dec 16 '10 at 4:58
    
@Dennis, thats very cool, some information on the errors would be highly valuable. How and where do i exactly set those in my htaccess? –  Sam Dec 16 '10 at 6:10
show 1 more comment

Try:

RewriteCond %{REQUEST_URI} %/IMG.*$ [NC]
share|improve this answer
    
Hello dmah, thanks for your suggestion, BUT, after changing the old cond to new cond, and changing IMG to MUFFINTOPS the rewrite rules still all fire correctly... i dont get it! –  Sam Dec 15 '10 at 21:40
add comment

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.