1

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
Sam
  • 403
  • 3
  • 7
  • 23

2 Answers2

1

Try:

RewriteCond %{REQUEST_URI} %/IMG.*$ [NC]
dmah
  • 516
  • 3
  • 5
  • 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
1

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

Rewrite Control Flow

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
  • 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 04: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 04: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 06:10
  • @Dennis, a look into my current htaccess file: perhaps this will shed some light into the matter: http://serverfault.com/questions/213191/does-is-matter-in-what-order-rules-are-placed-in-htaccess – Sam Dec 16 '10 at 08:23