为什么这个图片网址重写规则不起作用?

问题描述 投票:0回答:2

我写了一个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
2个回答
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>

0
投票

这就是最终工作的结果,但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>
© www.soinside.com 2019 - 2024. All rights reserved.