【发布时间】:2018-08-25 00:46:24
【问题描述】:
我很可能会遗漏一些东西。我在这篇很棒的帖子中找到了这个 URL 重写示例:http://marisks.net/2017/05/14/changing-static-resource-urls-to-cdn-urls-with-url-rewrite/
我的设置是相同的。我的代码中有相对 URL,我想即时重写它们以指向我的 CDN。
<outboundRules>
<clear />
<rule name="CDN" preCondition="CheckHTML" enabled="false" stopProcessing="true">
<match filterByTags="Img, Link, Script, CustomTags" customTags="Video" pattern="(^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*\.(jpg|jpeg|png|js|css|mp4).*)" />
<action type="Rewrite" value="http://cdn.example.com{R:1}" />
<conditions logicalGrouping="MatchAll">
</conditions>
</rule>
<preConditions>
<preCondition name="CheckHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
<customTags>
<tags name="Video">
<tag name="source" attribute="src" />
</tags>
</customTags>
</outboundRules>
这很好用。 除了我需要对特定文件夹的重写进行微调。 我知道这听起来很简单,但是当我查看上述脚本中的正则表达式时 - 我看不到在哪里可以对我的相对 URL 中的单词进行任何类型的限制。显然我需要在 Regex 上更加努力。但我们感谢您提供任何帮助。
我只需要捕获与某些文件夹的相关链接,例如 /media 或 /css(“/media/media.mp4”或“/css/base.css”)。
【问题讨论】:
标签: asp.net iis url-rewriting url-rewrite-module