srcset 的 IIS 出站重写规则仅重写一次
IIS Outbound Rewrite Rule for srcset only rewrite once
我在 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 属性中的所有值有什么帮助吗?
您可以使用以下重写规则:
<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>
此致,
贾尔帕
我在 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 属性中的所有值有什么帮助吗?
您可以使用以下重写规则:
<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>
此致, 贾尔帕