IIS Url Rewrite: 如何处理图片源srcset?
IIS Url Rewrite: How to handle picture source srcset?
我有一个网站,我正在使用 IIS UrlRewrite 进行反向代理。到目前为止,由于 Paul Cociuba 在 Microsoft Tech Community.
上发表的三篇文章,我已经度过了一段相当轻松的时光
我目前的挑战是 <picture><source srcset
中的一组 url,这些 url 被严重缩写,
<source srcset="/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-5.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 1400w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-6.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 2000w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-7.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 2800w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-1.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 350w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-2.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 460w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-3.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 700w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-4.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 920w"
media="(max-width: 768px)"
sizes="(max-width: 768px) 100vw">
如何将所有以 /a/b/c
开头的路径转换为 https://othersite/a/b/c
?在最坏的情况下,我也许可以编写一个正则表达式来捕获固定数量的路径(比如 7),然后用 {R:1} 到 {R:7} 重写它们,但此时我不确定项目的数量是否在每个 srcset
是固定的。
此外,我是否需要创建自定义标签以匹配 <source srcset=
?
这有效,我很惊讶。我仍然没有从页面上得到我期望的响应(一些图像仍然没有绘制),但至少 HTML 看起来是正确的。
首先,我声明了一个自定义标签
<customTags>
<tags name="sourceSrcset">
<tag name="source" attribute="srcset" />
</tags>
</customTags>
那我写了一个出站规则来使用它
<rule name="source srcset" preCondition="ResponseIsTextHtml">
<match filterByTags="CustomTags" customTags="sourceSrcset" pattern=",?\/(a\/b\/\S+\s\d+w)" />
<action type="Rewrite" value="https://othersite/{R:1}" />
</rule>
如果您想知道,ResponseIsTextHtml
有一个兄弟叫 ResponseIsTextAnything
,他们被声明为
<preCondition name="ResponseIsTextHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="ResponseIsTextAnything">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
</preCondition>
我有一个网站,我正在使用 IIS UrlRewrite 进行反向代理。到目前为止,由于 Paul Cociuba 在 Microsoft Tech Community.
上发表的三篇文章,我已经度过了一段相当轻松的时光我目前的挑战是 <picture><source srcset
中的一组 url,这些 url 被严重缩写,
<source srcset="/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-5.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 1400w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-6.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 2000w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-7.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 2800w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-1.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 350w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-2.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 460w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-3.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 700w,
/a/b/c/d/e/en/g/h/thumb%20classes%202020_SX_MX.component.crop-3x2-4.ts=1592419103694.jpg/a/c/d/oceania/au/en/g/jcr:a/root/z_1_col/z_4_col/image_1558468008 920w"
media="(max-width: 768px)"
sizes="(max-width: 768px) 100vw">
如何将所有以 /a/b/c
开头的路径转换为 https://othersite/a/b/c
?在最坏的情况下,我也许可以编写一个正则表达式来捕获固定数量的路径(比如 7),然后用 {R:1} 到 {R:7} 重写它们,但此时我不确定项目的数量是否在每个 srcset
是固定的。
此外,我是否需要创建自定义标签以匹配 <source srcset=
?
这有效,我很惊讶。我仍然没有从页面上得到我期望的响应(一些图像仍然没有绘制),但至少 HTML 看起来是正确的。
首先,我声明了一个自定义标签
<customTags>
<tags name="sourceSrcset">
<tag name="source" attribute="srcset" />
</tags>
</customTags>
那我写了一个出站规则来使用它
<rule name="source srcset" preCondition="ResponseIsTextHtml">
<match filterByTags="CustomTags" customTags="sourceSrcset" pattern=",?\/(a\/b\/\S+\s\d+w)" />
<action type="Rewrite" value="https://othersite/{R:1}" />
</rule>
如果您想知道,ResponseIsTextHtml
有一个兄弟叫 ResponseIsTextAnything
,他们被声明为
<preCondition name="ResponseIsTextHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="ResponseIsTextAnything">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
</preCondition>