网址重写规则不会忽略文件请求 [英] url rewrite rule does not ignore request for file

查看:91
本文介绍了网址重写规则不会忽略文件请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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。

The above is a one of several url rewrite rules widely suggested for angular single page apps. I understand the rule to mean "If the request is not for a physical file, rewrite the url to /index.html.

上面文档链接的节选:这可以用来指定一个条件,该条件检查所请求的URL是否不是文件...

Excerpt from documentation link above: " This can be used to specify a condition that checks if the requested URL is NOT a file..."

在index.html中,我有此脚本参考:

In index.html I have this script reference:

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

这是一个物理文件,确实存在于指定位置的磁盘上。
重写规则是接收此请求并将其重写到/index.html。

为什么会发生呢?
我的web.config与wwwroot位于同一级别。

This is a physical file and it does exist on the disk in the location specified.
The rewrite rule is picking up this request and rewriting it to /index.html.
Why is that occuring? My web.config is located at the same level as wwwroot.

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

There are several threads on github related to url rewrites, not sure if this specific issue is covered: 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 Core应用程序,该文件位于子目录中。

IsFile won't work because the file is not where IIS expects it to be. For an Asp.Net 4 app the index.html file would have been in the site root, but for an Asp.Net Core app the file is in a subdirectory.

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

Try using the new Rewrite middleware instead, it knows where the files are in the new Asp.Net Core layout. https://github.com/aspnet/BasicMiddleware/blob/dev/samples/RewriteSample/Startup.cs#L16

这篇关于网址重写规则不会忽略文件请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆