IIS url rewrite - css and js overwrite incorrectly

I have a problem with my urlrewrites - at any time I point to the page that needs to be rewritten, it does not appear, because it also applies the rule to the css and js files that are listed on my web page.

To try and fix this, I entered the full path to css and js - this perfectly displays any page on which rewrite is not applied when I try to access a rewritten page that freezes my browser.

Has anyone come across something similar, and if you have a solution? Appreciate any help. I tried to look at the site on similar issues, but so far no one has helped.

<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> 

on my webpage:

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

he applies the rewriting to them and tries to find /myapplicationname/Team/Styles/MainStyle.css and similarly with the JS file.

+6
source share
1 answer

Try to figure out which rule is causing the problem by deleting them one at a time. Now add the condition to this rule:

  <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> 

This will avoid running the rule in files ending in .js, .css, etc.

+4
source

Source: https://habr.com/ru/post/898489/


All Articles