【问题标题】:IIS Outbound Rewrite Rule for srcset with multiple URLs具有多个 URL 的 srcset 的 IIS 出站重写规则
【发布时间】:2016-04-06 20:20:56
【问题描述】:

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

【问题讨论】:

    标签: iis url-rewriting rewrite outbound


    【解决方案1】:

    如下更改您的规则:

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

    【讨论】:

    • 另外,规则应该包括:stopProcessing="false"
    • 工作就像一个魅力。我不需要规则标签上的stopProcessing="false",尽管添加它并没有什么坏处。
    猜你喜欢
    • 2020-01-05
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 2014-05-01
    相关资源
    最近更新 更多