1

i need some help to write two URL rewrite rules in IIS7, i have tried for the last 3 hours with no success.

Basically, i have the following two rules:

<rule name="Resize Images - Game Thumbnails - Static" stopProcessing="true">
    <match url="^images/c/games/(.+)x(.+)/(.+)$" />
    <conditions logicalGrouping="MatchAny">
        <add input="\mycms\games\images\thumbs\220x150\{R:3}" matchType="IsFile" negate="true" />
    </conditions>
    <action type="Rewrite" url="/mycms/games/images/thumbs/{R:1}x{R:2}/{R:3}" />
</rule>
<rule name="Resize Images - Game Thumbnails - Dynamic" stopProcessing="true">
    <match url="^images/c/games/(.+)x(.+)/(.+)$" />
    <conditions logicalGrouping="MatchAny">
        <add input="\mycms\games\images\thumbs\{R:1}x{R:2}\{R:3}" matchType="IsFile" negate="true" />
    </conditions>
    <action type="Rewrite" url="/controls/makeThumb.aspx?folder=games&amp;image={R:3}&amp;w={R:1}&amp;h={R:2}" />
</rule>

Both of the rules work if they are alone.

for example, if i put only the static rule, and the image exists, Then it returns the image.

if i leave only the dynamic rule, and the image does not exist, then it is created.

but why don't the rules work together?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93

1 Answers1

5

Well i found the problem, basicly both of these rules work:

        <rule name="Resize Images - Game Thumbnails - Static" stopProcessing="true">
            <match url="^images/c/games/(.+)x(.+)/(.+)$" />
            <conditions logicalGrouping="MatchAny">
                <add input="{APPL_PHYSICAL_PATH}mycms\games\images\thumbs\{R:1}x{R:2}\{R:3}" matchType="IsFile" />
            </conditions>
            <action type="Rewrite" url="/mycms/games/images/thumbs/{R:1}x{R:2}/{R:3}" />
        </rule>
        <rule name="Resize Images - Game Thumbnails - Dynamic" stopProcessing="true">
            <match url="^images/c/games/(.+)x(.+)/(.+)$" />
            <conditions logicalGrouping="MatchAny">
                <add input="\mycms\games\images\thumbs\{R:1}x{R:2}\{R:3}" matchType="IsFile" negate="true" />
            </conditions>
            <action type="Rewrite" url="/controls/makeThumb.aspx?folder=games&amp;image={R:3}&amp;w={R:1}&amp;h={R:2}" />
        </rule>

BUT!!!! and this is a big but, if you delete the image ( for testing purposes or whatever ) the rule is somehow cached, and for some bizzare reason, the dynamic rule will not execute. the only way to force it to execute, is to recycle the application pool.

Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93
  • I'm not sure if you're using an external file for the rewrite rules, but I know that that scenario does not reload the rules when something changes: http://stackoverflow.com/questions/3767864/iis7-urlrewrite-module-rules-in-external-xml-file – Grimace of Despair Oct 03 '12 at 08:25
  • 1
    Thanks for mentioning {APPL_PHYSICAL_PATH} (I needed that for a problem I was working on). The problem with the deleted image you mention is caused by caching, either by IIS or URLRewrite itself (not sure). If you continue to hit the URL, the presence of the file will remain in cache. However if you don't request the URL for 60 seconds, it will check for the file again and realize it isn't there (anymore). – Marco Miltenburg Nov 21 '14 at 14:14