首页 > 解决方案 > srcset 的 IIS 出站重写规则仅重写一次

问题描述

我在 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 属性中的所有值?

标签: iisurl-rewritingweb-config

解决方案


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

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

在此处输入图像描述

问候,贾尔帕。


推荐阅读