0

I have tried to solve the issue of not getting css and images files loaded in browser after url rewriting in IIS for classic asp app. I have found the solution which shows in developer tool's network tab that files are loaded (Status Code: 200 OK) and css and image urls are now pointing to correct folders - but file contents don't just get loaded. Here is the web.config based on the solution (How to fix URL Rewriting for links inside CSS files with IIS7):

  <rule name="Rewrite css URLs" preCondition="IsCSS" stopProcessing="true">
      <match pattern="localhost/asp-app/data/styles" />
      
      <action type="Rewrite" value="localhost/asp-app/styles" />
  </rule>
  <preConditions>
      <preCondition name="IsCSS">
          <add input="{RESPONSE_CONTENT_TYPE}" pattern="text/css" />
      </preCondition>
  </preConditions>

    </outboundRules>

<rules>
        <rule name="Rewrite-to-http-verbs-handler">
            <match url=".*" />
            <action type="Rewrite" url="/asp-app/routes/router2.asp" />
        </rule>
    </rules>
</rewrite>

correct css-file path after rewrite rule

response header information is ok

And even though I use absolute url in the css-link tag in the head section

<link rel="stylesheet" href="http://localhost/asp-app/styles/test.css">,

the css don't not get loaded. And the same is with images, even full urls are not working, ie.

<img src="http://localhost/asp-app/images/konsultaatio.jpg" />

Any ideas how to fix?

user692942
  • 16,398
  • 7
  • 76
  • 175
M.Y.
  • 549
  • 1
  • 3
  • 23

2 Answers2

0

I eventually found the solution for the issue. It is based on what is presented here: https://community.progress.com/s/article/Sitefinity-backend-not-working-correctly-when-using-rewrite-rules

So, what was needed to fix the issue was to add a rule to prevent css, images, and also js -files to be loaded simultaneously with the asp-file rewriting. Note that the rule for the

action type="None"

has to precede the asp-file rewriting rule.

<rewrite>
  <rules>
    <rule name="preventRewriteRulesFor" stopProcessing="true">
        <match url="^/?(styles|images|js)/" ignoreCase="true" />
        <action type="None" />
    </rule>
    <rule name="Rewrite" stopProcessing="true">
        <match url=".*" />
        <action type="Rewrite" url="/asp-app/routes/router2.asp" />
    </rule>
  </rules>
</rewrite>

I realized the solution when I saw in the network tab for the browser tools that css, js and even images response raw data was the very same as was the loaded html-content of the asp file. Thus, css, js and image files had to be prevented from being automatically rewritten along with the rule for asp-file.

Therefore, also, I could skip the outboundRules and preConditions altogether given in the original question - they are not needed.

M.Y.
  • 549
  • 1
  • 3
  • 23
-1

When you directly access the rewritten URL in the browser, can the file be loaded normally? You need to check whether the folders where the CSS files and images are located have access permissions to ensure that the IIS user can read the files normally.

YurongDai
  • 1,362
  • 1
  • 2
  • 7
  • No, when I directly access the css-file (or images from their folder) they do not either get loaded in the browser. And if I give full rights to the IIS-users, it does not change the situation. – M.Y. Jun 02 '23 at 15:42