简体   繁体   English

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

[英]IIS Outbound Rewrite Rule for srcset with multiple URLs

I have something like this in my html response:我的 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" />

I'd like to use IIS outbound rewrite rule to replace all references to www.test.com with www.foo.com.我想使用 IIS 出站重写规则将所有对 www.test.com 的引用替换为 www.foo.com。 How can I do this when an attribute (in this case the srcset ) has multiple instances of the URL?当属性(在本例中为srcset )具有多个 URL 实例时,我该如何执行此操作?

Here's what my rule currently looks like:这是我的规则目前的样子:

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

But of course only the first URL in each attribute gets overwritten:但当然只有每个属性中的第一个 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" />

How can I rewrite all instances of www.test.com to www.foo.com ?如何将www.test.com所有实例重写为www.foo.com

Change your rule as follows:更改规则如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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