当URL中间有一个点时,改写器会出错

When a dot exist in the middle of the URL, the rewriter works wrong

我在 asp net core 2.0 中有一个项目。

我已经在 web.config 中建立了下一条规则:

<rewrite>
    <rules>
        <rule name="wwwroot" >
            <match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
            <action type="Rewrite" url="wwwroot/{R:1}" logRewrittenUrl="true" />
        </rule>
    </rules>
</rewrite> 

当我访问 url 时:www.foobar.com/lib/chart.js/dist/Chart.js 出于某种原因,iis 试图在 Chart.js路径:wwwroot/lib/chart.js 忽略了 url (/dist/Chart.js) 的最后一部分,而我希望使用 wwwroot/lib/chart.js/dist/Chart.js

尝试像这样修改您的正则表达式:([\S]+[.](js|css|png|gif|jpg|jpeg))$ 如果文件扩展名位于 url

的末尾,则应考虑文件扩展名

编辑

根据您的规则,您应该排除从 wwwroot

开始的 url
    <rule name="wwwroot" >
        <match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
        <conditions logicalGrouping="MatchAll">
             <add input="{REQUEST_URI}" negate="true" pattern="^/wwwroot" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="wwwroot/{R:1}" logRewrittenUrl="true" />
    </rule>