IIS 7.5使用ip地址将某些请求重定向到其他服务器

时间:2017-07-05 07:55:17

标签: asp.net redirect iis

这是我一直在苦苦挣扎的问题 我在服务器I 中托管了地址为(.*jpg.*)的网站,但该网站的图片来自服务器II (IP:1.2.3.4),所以如果有请求 www.mywebsite.com/images/123.jpg 我想将它们重定向到图像服务器( Server II )。

我希望包含<rewrite> <rules> <rule name="Ignore images requests" enabled="true" stopProcessing="true"> <match url="(.*jpg.*)" /> <action type="Rewrite" url="https://www.petfinder.com/wp-content/uploads/2012/11/91615172-find-a-lump-on-cats-skin-632x475.jpg" /> </rule> </rules> </rewrite> regex的请求会重定向到 Server II

  1. 使用Url重写我添加了一条规则:

    {{1}}
  2. 如您所见,它会将请求重写为静态图像,如何定义它以转到 1.2.3.4/images/imagename.jpg

    最好的解决方案是,如果我可以通过我的主机文件忽略包含 jpg 的请求,是否有办法实现?

1 个答案:

答案 0 :(得分:1)

您的重定向规则应该是这样的:

<rule name="image redirect" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" pattern="(.*?)\.jpg$" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" />
    </conditions>
  <action type="Redirect" url="http://1.2.3.4/{R:1}" appendQueryString="false" />                           
</rule>

它会将所有请求重定向到.jpg扩展名为1.2.3.4域的文件 例如:

http://www.mywebsite.com/dog-1210559_960_720.jpghttp://1.2.3.4/dog-1210559_960_720.jpg

http://www.mywebsite.com/UserFiles/Entities/TopBanners/top50161616‌​_586.jpghttp://1.2.3.4/UserFiles/Entities/TopBanners/top50161616‌​_586.jpg