【问题标题】:url rewrite rule does not ignore request for fileurl 重写规则不会忽略对文件的请求
【发布时间】:2016-09-23 01:34:47
【问题描述】:

http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    <rule name="AngularJS Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

      </conditions>
      <action type="Rewrite" url="/index.html" />
    </rule>

以上是针对 Angular 单页应用程序广泛建议的几个 url 重写规则之一。 我理解该规则的意思是“如果请求不是针对物理文件,请将 url 重写为 /index.html。

摘自以上文档链接:“这可用于指定检查请求的 URL 是否不是文件的条件...”

在 index.html 我有这个脚本参考:

<script src="lib/jquery/dist/jquery.min.js"></script>

这是一个物理文件,它确实存在于指定位置的磁盘上。
重写规则是接收这个请求并将其重写到 /index.html。
为什么会这样? 我的 web.config 与 wwwroot 位于同一级别。

github上有几个与url重写相关的线程,不确定是否涵盖了这个特定问题: https://github.com/aspnet/BasicMiddleware/issues/43 https://github.com/aspnet/IISIntegration/issues/164 https://github.com/aspnet/IISIntegration/issues/192

【问题讨论】:

    标签: url-rewriting asp.net-core .net-core


    【解决方案1】:

    IsFile 不起作用,因为该文件不在 IIS 预期的位置。对于 Asp.Net 4 应用程序,index.html 文件应位于站点根目录中,但对于 Asp.Net Core 应用程序,该文件位于子目录中。

    尝试改用新的 Rewrite 中间件,它知道文件在新的 Asp.Net Core 布局中的位置。 https://github.com/aspnet/BasicMiddleware/blob/dev/samples/RewriteSample/Startup.cs#L16

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-14
    • 2012-02-13
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2018-11-13
    相关资源
    最近更新 更多