具有多个 URL 的 srcset 的 IIS 出站重写规则

IIS Outbound Rewrite Rule for srcset with multiple URLs

我的 html 回复中有这样的内容:

<img 
  src="http://www.test.com/image1.jpg"
  srcset="http://www.test.com/image1-300x200.jpg 300w, http://www.test.com/image1.jpg 600w" sizes="(max-width: 600px) 100vw, 600px" />

我想使用 IIS 出站重写规则将对 www.test.com 的所有引用替换为 www.foo.com。当属性(在本例中为 srcset)具有多个 URL 实例时,我该如何执行此操作?

这是我的规则目前的样子:

<outboundRules>
    <rule name="Blog Paths" preCondition="IsBlog">
        <match filterByTags="Img, CustomTags" customTags="BlogTags" pattern="^http://www.test.com(.*)$" />
        <action type="Rewrite" value="http://www.foo.com{R:1}" />
    </rule>
    <preConditions>
        <preCondition name="IsBlog">
            <add input="{RESPONSE_Content_Type}" pattern="^text/html" />
            <add input="{RESPONSE_X_Content_Source}" pattern="^blog" />
        </preCondition>
    </preConditions>
    <customTags>
        <tags name="BlogTags">
            <tag name="img" attribute="srcset" />
        </tags>
    </customTags>
</outboundRules>

但当然只有每个属性中的第一个 URL 被覆盖:

<img 
  src="http://www.foo.com/image1.jpg"
  srcset="http://www.foo.com/image1-300x200.jpg 300w, http://www.test.com/image1.jpg 600w" sizes="(max-width: 600px) 100vw, 600px" />

如何将 www.test.com 的所有实例重写为 www.foo.com

按如下方式更改您的规则:

    <match filterByTags="Img, CustomTags" customTags="BlogTags" pattern="(.*)http://www.test.com(.*)" />
    <action type="Rewrite" value="{R:1}http://www.foo.com{R:2}" />