IIS URL重写模块-URL的正则表达式

ugmeyewa  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(127)

我想重定向以下旧URL:

https://domain1.xyz.com/content/images/1ca9551bc00357f63c608b5d90ca7c4652187487.png

到新的URL:

https://domain2.xyz.com/originalfiles/1ca9551bc00357f63c608b5d90ca7c4652187487.png

我的web.config文件具有以下配置,但我无法使其工作:

<rewrite>
       <rules>
          <rule name="Rewrite Images to CDN" stopProcessing="true">
                <match url="(.*)" />
                <action type="Redirect" url="https://domain2.xyz.com/originalfiles/{C:1}" appendQueryString="true" redirectType="Permanent" />
                <conditions>
                   <add input="{HTTP_HOST}" pattern="domain1.xyz.com" />
                   <add input="{URL}" pattern="content/images/(/*.*)" />
                </conditions>
         </rule>
       </rules>
</rewrite>

以上配置重定向到此URL,但此URL不正确:

https://domain2.xyz.com/originalfiles/content/images/1ca9551bc00357f63c608b5d90ca7c4652187487.png
nkoocmlb

nkoocmlb1#

请尝试以下规则:

<rewrite>
       <rules>
          <rule name="Rewrite Images to CDN" enabled="true" stopProcessing="true">
                <match url="content/images(.*)" />
                <conditions>
                   <add input="{HTTP_HOST}" pattern="domain1.xyz.com" />
                </conditions>
                <action type="Redirect" url="https://domain2.xyz.com/originalfiles{R:1}" />
           </rule>
        </rules>
</rewrite>

相关问题