【问题标题】:IIS Rewrite rule - check if a static file existsIIS 重写规则 - 检查静态文件是否存在
【发布时间】:2014-07-19 04:02:42
【问题描述】:

谁能告诉我如何检查静态文件是否存在作为重写规则条件。

我在 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。如果我注释掉检查文件的第二个条件,它就可以工作。有了条件,它就失败了。

【问题讨论】:

标签: asp.net-mvc iis rewrite iis-8


【解决方案1】:

因为它在没有 &lt;add input="/favicon.ico" matchType="IsFile" /&gt; 行的情况下工作,所以我怀疑该行。

我猜这与您的 /favicon.ico 路径有关,因为 matchType="IsFile" 是正确的。

有关更多示例,请参阅 this link,他们的解决方案是不使用正斜杠 (/),而是使用反斜杠 (\)。

但我必须在 行中使用非斜杠 (/)。我必须使用 BACKSLASH()。那行是正确的:

【讨论】:

  • 谢谢 :) 对我来说,导致它的原因是缺少对 {DOCUMENT_ROOT} 的引用。所以我需要&lt;add input="{DOCUMENT_ROOT}/favicon.ico" matchType="IsFile" /&gt;
猜你喜欢
  • 2011-11-27
  • 1970-01-01
  • 2019-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
相关资源
最近更新 更多