How to fix URL Correspondence for links inside CSS files using IIS7

I am trying to set up a proxy server for my friends at home. I am currently following a tutorial on the website ( http://blogs.iis.net/carlosag/archive/2010/04/01/setting-up-a-reverse-proxy-using-iis-url-rewrite-and -arr.aspx ), but I ran into some strange problem.

I tried making / pandora redirect to www.pandora.com, but the links inside the CSS files do not change. In addition, they are still connected to the localhost / img / ... host. They should be redirected to the localhost / pandora / img / ...

sniplet from the first web page

<link rel="shortcut icon" href="/pandora/favicon.ico" type="image/x-icon" /> <link rel="icon" type="image/ico" href="/pandora/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="css/compiled.css?v=95845013"> <link id="valanceStyle" rel="stylesheet" type="text/css" href="/pandora/static/valances/pandora/default/design.css"/> 

Can you help me solve this problem?

+7
source share
1 answer

This can be done using an outbound rewrite rule in conjunction with ARR. The following rule should do this:

 <system.webServer> <rewrite> <outboundRules> <rule name="Rewrite image URLs in CSS response" preCondition="IsCSS"> <match pattern="localhost/img/" /> <action type="Rewrite" value="localhost/pandora/img/" /> </rule> <preConditions> <preCondition name="IsCSS"> <add input="{RESPONSE_CONTENT_TYPE}" pattern="text/css" /> </preCondition> </preConditions> </outboundRules> </rewrite> </system.webServer> 

Of course, you must replace localhost with the correct domain names. If you are rewriting a different domain name, the match tag must contain the name of the domain that you want to replace, and the action tag must contain the name of the domain that you want to replace.

Since CSS is not HTML, you cannot use the tag filtering function of the URL rewrite module. Thus, it can only perform regular expression matching with all the contents of the CSS file, which could potentially be intensively loaded by the CPU on large CSS files. If you know how many URLs you need to replace, you can add the occurrences="x" attribute to the <match> tag to limit the number of matches that the URL rewrite module should look for. Also try moving CSS rules to the top of the CSS file. For example:.

 <action type="Rewrite" value="localhost/pandora/img/" occurrences="3" /> 

You can also enable user-mode caching in IIS and add the rewriteBeforeCache="yes" attribute to the <outboundRules> tag so that IIS caches overwrite content. For example:.

 <outboundRules rewriteBeforeCache="yes"> 

More useful information and tips on rewriting rules can be found in this blog post .

+11
source

All Articles