【问题标题】:Why isn't this image URL Rewrite rule working?为什么此图像 URL 重写规则不起作用?
【发布时间】:2018-08-11 08:25:22
【问题描述】:

我已经编写了 URL 重写来修复图像路径以移动到图像的新位置,但是它不起作用。

<rule name="Artist Images" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{URL}" pattern="^/images/$" />
      </conditions>
      <action type="Rewrite" url="https://myserver.blob.core.windows.net/v2/images/" redirectType="Permanent" />
    </rule>

预期的行为是,当图像请求进入 (http://myserver.com/images/sample.jpg) 时,新图像位置 (https://myserver.blob.core.windows.net/v2/images/sample.jpg) 被使用。

它是托管在 Azure 上的 .net 应用程序。规则在 web.config 中。
有什么想法吗?

【问题讨论】:

    标签: asp.net azure url-rewriting web-config imageurl


    【解决方案1】:

    因为您的条件不正确,所以您输入符号 $ 表示字符串的结尾,但这是不正确的。

    <rule name="Artist Images" stopProcessing="true">
      <match url="^images/(.*)$" />
      <action type="Rewrite" url="https://myserver.blob.core.windows.net/v2/images/{R:1}" />
    </rule>
    

    【讨论】:

      【解决方案2】:

      这最终奏效了,但 Alexey 的回答让我们朝着正确的方向前进。

         <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
          <add input="{HTTP_URL}" pattern="/images/(.*)" />
          </conditions>
          <action type="Redirect" url="https://artistshare.blob.core.windows.net/images/{C:1}" />
          </rule>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多