0

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;)" />
    <conditions>
        <add input="{URL}" pattern="/zeus" />
    </conditions>
</rule>

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

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

Thank you beforehand.

1

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.

3
  • 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. Oct 24 '12 at 4:15
  • So your pattern is now url\(&quot;(.*?)&quot;\) in the match element? Oct 24 '12 at 4:19
  • Nevermind, I did it wrong! Thank you, it works now! Oct 24 '12 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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