使用以下规则,我可以成功重写 url 以重定向到 app/index.cshtml。不应重定向图像、css 和 javascripts 等一些资源,因此我使用了条件:
<rule name="AngularJS">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" negate="true" pattern="\.png$" />
<add input="{URL}" negate="true" pattern="\.css$" />>
<add input="{URL}" negate="true" pattern="\.js$" />
</conditions>
<action type="Rewrite" url="app/index.cshtml" />
</rule>
但是一旦我开始使用缩小的内容,请求的 URL 就会变得类似于:
/myapp/bundles/utilities?v=EH9YuZDBt_fj7iqRP2QA8lCkJ59wjV6woELIwvR7irk1
如何防止这种类型的 url 被重定向?
最佳答案
您可以创建忽略规则,匹配要忽略的 URL
<rule name="Ignore" enabled="true" stopProcessing="true">
<match url="^(images|css|bundles).*"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
<action type="None"/>
</rule>
关于IIS 网址重写 : how to ignore minified javascript and css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212714/