srcset的IIS出站重写规则仅重写一次

时间:2019-04-23 10:17:14

标签: iis url-rewriting web-config

我在II上创建一个outboundRule来更改html中的文本时遇到一个问题。问题是当它仅更改最后一个匹配项时,它位于srcset属性的img标签内。

我已经尝试过了:

<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>

似乎是正确的,但我的结果是:

<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">

是否有帮助,要更改srcset属性中的所有值?

1 个答案:

答案 0 :(得分:0)

您可以使用以下重写规则:

 <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>

enter image description here

关于, 贾帕。