如何用查询字符串中的数据重写Azure图像url

本文关键字:重写 Azure 图像 url 数据 何用 查询 字符串 | 更新日期: 2023-09-27 18:14:13

我有一个Azure网站托管了一组我在Windows Phone应用程序中用于Live Tiles的图像

Live Tile图像请求对URL中的比例(和其他)数据进行编码,就像这样(我认为,这方面的文档非常缺乏)

http://example.com/Images/sunny.png?ms-scale=100& ms-contrast =标准amp; ms-lang = en - us

我想把它重写为

http://example.com/images/sunny.scale - 100. - png

其中。scale-xxx值与查询字符串

如何用查询字符串中的数据重写Azure图像url

中的值匹配

经过大量的搜索,我终于明白了

<system.webServer>
    <rewrite>
      <rules>
        <rule name="SpecificRewrite" stopProcessing="true">
          <conditions>
              <add input="{QUERY_STRING}" pattern=".*ms-scale=('d+).*"  />
          </conditions>
          <match url="^Images/(.*).png.*" />
          <action type="Rewrite" url="/Images/{R:1}.scale-{C:1}.png" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>

这将查询字符串添加到匹配(组引用为C:1)

<add input="{QUERY_STRING}" pattern=".*ms-scale=('d+).*"  />

这是实际匹配(组引用为R:1)

<match url="^Images/(.*).png.*" />

重写规则

<action type="Rewrite" url="/Images/{R:1}.scale-{C:1}.png" />

参考资料

  • URL重写模块配置参考
  • 轻松调试和故障排除重写规则

您可以在Azure网站管理门户的配置部分中打开失败请求跟踪,文件最终在/LogFiles/<SiteName>/