[英]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}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.