http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference 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 重写规则之一。
我理解该规则的意思是“如果请求不是针对物理文件,则将 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/BasicMiddleware/issues/43
https://github.com/aspnet/IISIntegration/issues/164 https://github.com/aspnet/IISIntegration/issues/164
https://github.com/aspnet/IISIntegration/issues/192 https://github.com/aspnet/IISIntegration/issues/192
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 https://github.com/aspnet/BasicMiddleware/blob/dev/samples/RewriteSample/Startup.cs#L16
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)