Can someone tell me how to check if a static file exists as a rewrite rule condition.
I'm on IIS8, and my web app is it's own web site. I want to add a rewrite rule that checks if afile exists, and if so then applies the rewrite. Here's my code:
<rewrite>
<rules>
<rule name="Find static gravatar" stopProcessing="true">
<match url="^images/animage.png$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="i=(.+)" />
<add input="/favicon.ico" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="/Somewhere/Else/images/{C:1}.png" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Hitting URL /images/animage.png?i=SS
In desperation I'm checking for a file I know exists - favicon.ico. If I comment out the 2nd condition that checks for the file, it works. With the condition in, it fails.
As it works without the <add input="/favicon.ico" matchType="IsFile" />
line, that line is suspect to me.
I'd have to guess it has to do with your /favicon.ico
path, as the matchType="IsFile"
is correct.
See this link for more examples, their resolution was to not use a forward slash (/) but instead use a backslash (\).
But I must to use not slash (/) in line <add input="{DOCUMENT_ROOT}/{R:1}" matchType="IsDirectory" negate="true" />. I must to use BACKSLASH (). That line is right: <add input="{DOCUMENT_ROOT}{R:1}" matchType="IsDirectory" negate="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With