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
1
  • 2
    Because it's lazy! Nyuk nyuk nyuk.
    – mfinni
    Dec 15, 2010 at 19:14

2 Answers 2

1

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

Rewrite Control Flow

6
  • 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, 2010 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. Dec 15, 2010 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, 2010 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? Dec 16, 2010 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, 2010 at 6:10
1

Try:

RewriteCond %{REQUEST_URI} %/IMG.*$ [NC]
1
  • 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, 2010 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .