url 重写规则不忽略文件请求
url rewrite rule does not ignore request for file
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>
以上是 url 为 angular 单页应用广泛建议的重写规则之一。
我理解规则的意思是“如果请求不是物理文件,请将 url 重写为 /index.html。
以上文档 link 的摘录:“这可用于指定检查请求的 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
IsFile 将无法工作,因为该文件不在 IIS 期望的位置。对于 Asp.Net 4 应用程序,index.html 文件将位于站点根目录中,但对于 Asp.Net 核心应用程序,该文件位于子目录中。
尝试改用新的 Rewrite 中间件,它知道文件在新的 Asp.Net 核心布局中的位置。
https://github.com/aspnet/BasicMiddleware/blob/dev/samples/RewriteSample/Startup.cs#L16
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>
以上是 url 为 angular 单页应用广泛建议的重写规则之一。 我理解规则的意思是“如果请求不是物理文件,请将 url 重写为 /index.html。
以上文档 link 的摘录:“这可用于指定检查请求的 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
IsFile 将无法工作,因为该文件不在 IIS 期望的位置。对于 Asp.Net 4 应用程序,index.html 文件将位于站点根目录中,但对于 Asp.Net 核心应用程序,该文件位于子目录中。
尝试改用新的 Rewrite 中间件,它知道文件在新的 Asp.Net 核心布局中的位置。 https://github.com/aspnet/BasicMiddleware/blob/dev/samples/RewriteSample/Startup.cs#L16