IIS url重写- css和js被错误地重写

IIS url rewrite - css and js incorrectly being rewritten

本文关键字:重写 错误 js css url IIS      更新时间:2023-09-26

我的urlrewrites有一个问题-每当我指向一个要重写的页面时,它无法显示,因为它也将规则应用于css &在我的网页中引用的Js文件

为了解决这个问题,我在css和js中加入了一个完全限定的路径-这在任何未应用重写的页面上都可以很好地呈现,当我试图访问重写的页面时,浏览器会挂起。

有没有人遇到类似的事情,如果有,你有解决方案吗?感谢任何帮助。我试着在网站上寻找类似的问题,但到目前为止没有任何帮助。

<rewrite>
<outboundRules>
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1" stopProcessing="true">
<match filterByTags="A, Form, Img" pattern="^(.*/)myapplicationname/Index'.html'?team=([^=&amp;]+)$" />
<action type="Rewrite" value="{R:1}team/{R:2}/" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^myapplicationname/Index'.html$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Index.html?{R:1}={R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>

我的网页:

<script src="/myapplicationname/Scripts/jquery-1.4.1.js" type="text/javascript">    </script>
<link href="/myapplicationname/Styles/MainStyle.css" rel="stylesheet" type="text/css" />

它正在对这些应用重写,并试图找到/myapplicationname/Team/Styles/MainStyle.css和类似的JS文件

通过逐个删除它们来找出导致问题的规则。现在为该规则添加一个条件:

    <rule name="Some rule">
      ...
      <conditions logicalGrouping="MatchAny">
          <add input="{URL}" pattern="^.*'.(ashx|axd|css|gif|png|jpg|jpeg|js|flv|f4v)$" negate="true" /> 
      </conditions>
    </rule>

这将避免在以.js, .css等结尾的文件上运行该规则。