Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to rewrite certain CSS files with some rules, so it replaces every single instance of links in the CSS (as in background: url("/myuri.jpg")) with a prefix (as in background: url("/zeus/myuri.jpg"))

These are the rules.

<rule name="ReverseProxyOutboundRule2" preCondition="IsCSS" enabled="true" stopProcessing="false">
    <match filterByTags="None" pattern="url\(&quot;(.*)&quot;\)" />
    <action type="Rewrite" value="url(&quot;/zeus{R:1}&quot;)" />
        <add input="{URL}" pattern="/zeus" />

<preCondition name="IsCSS">
    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/css" />

However, only one url is being replaced this way and somehow the rest is being ignored.

Thank you beforehand.

share|improve this question
up vote 1 down vote accepted

It's your regular expression pattern.

You've used url\(&quot;(.*)&quot;\), which after hitting your first url will greedily match every character up to the last quote in your file. It's not obvious because your replacement simply prefixes the matched content, so it appears that only the first url was touched.

Try using a lazy quantifier, i.e. .*? inside your capture expression. This will match the fewest characters up to the next quote.

share|improve this answer
Done, and it doesn't work. I checked the source code and it replaces exactly one occurrence. The rest remains the same and there's no further modifications to the css file. – user1231958 Oct 24 '12 at 4:15
So your pattern is now url\(&quot;(.*?)&quot;\) in the match element? – Michael Petito Oct 24 '12 at 4:19
Nevermind, I did it wrong! Thank you, it works now! – user1231958 Oct 24 '12 at 4:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.