有人可以告诉我如何检查静态文件是否存在作为重写规则条件。
我在 IIS8 上,我的网络应用程序是它自己的网站。我想添加一个重写规则来检查文件是否存在,如果存在则应用重写。这是我的代码:
<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>
点击网址
/images/animage.png?i=SS
无奈之下,我正在检查我知道存在的文件 - favicon.ico。如果我注释掉检查文件的第二个条件,它就可以工作。在条件满足的情况下,它失败了。
最佳答案
因为它在没有 <add input="/favicon.ico" matchType="IsFile" />
的情况下工作线,那条线对我来说是可疑的。
我不得不猜测这与您的 /favicon.ico
有关路径,如 matchType="IsFile"
是正确的。
见 this link对于更多示例,他们的解决方案是不使用正斜杠 (/),而是使用反斜杠 (\)。
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" />
关于asp.net-mvc - IIS 重写规则 - 检查静态文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936893/