简体   繁体   中英

IIS Outbound Rewrite Rule for srcset only rewrite once

I have one problem with one outboundRule created on IIs to change text in html. The problem is inside img tag in srcset attribute when it only change last match.

I've tried this:

<outboundRules>
  <rule name="ReverseProxyOutboundRuleHTML" preCondition="ResponseIsHTML" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script, CustomTags" customTags="customTags" pattern="(.*)9999.99.99.99:8080(.*)" />
    <action type="Rewrite" value="{R:1}example.com{R:2}" />
  </rule>           
  <preConditions>
    <preCondition name="ResponseIsHTML"> 
      <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    </preCondition>
  </preConditions>
  <customTags>
    <tags name="customTags">
      <tag name="img" attribute="srcset" />
      <tag name="meta" attribute="content" />
    </tags>
  </customTags>
</outboundRules>

Seems to be correct, but my result is:

<img 
src="http://example.com/wp-content/uploads/2019/02/Mercedes_ClasseV-1024x540.png" 
srcset="http://9999.99.99.99:8080/wp-content/uploads/2019/02/Mercedes_ClasseV-1024x540.png 1024w, http://9999.99.99.99:8080/wp-content/uploads/2019/02/Mercedes_ClasseV-300x158.png 300w, http://9999.99.99.99:8080/wp-content/uploads/2019/02/Mercedes_ClasseV-768x405.png 768w, http://example.com/wp-content/uploads/2019/02/Mercedes_ClasseV.png 1100w" 
sizes="(max-width: 750px) 100vw, 750px">

Any help, to change all values in srcset attribute?

You could use below Rewrite rule:

 <outboundRules>
  <rule name="ReverseProxyOutboundRuleHTML" preCondition="ResponseIsHTML" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script, CustomTags" customTags="customTags" pattern="(.*)9999.99.99.99:8080(.*),(.*)9999.99.99.99:8080(.*)\,(.*)9999.99.99.99:8080(.*)" />
    <action type="Rewrite" value="{R:1}example.com{R:2},{R:3}example.com{R:4},{R:5}example.com{R:6}" />
  </rule>           
  <preConditions>
    <preCondition name="ResponseIsHTML"> 
      <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    </preCondition>
  </preConditions>
  <customTags>
    <tags name="customTags">
      <tag name="img" attribute="srcset" />
      <tag name="meta" attribute="content" />
    </tags>
  </customTags>
</outboundRules>

在此输入图像描述

Regards, Jalpa.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM