【问题标题】:IIS 7.5 redirect certain requests to other server using ip addressIIS 7.5 使用 IP 地址将某些请求重定向到其他服务器
【发布时间】:2017-12-08 18:22:57
【问题描述】:

这是我一直在努力解决的一个问题。
我在 server I 中托管了一个地址为 www.mywebsite.com 的网站,但该网站的图像来自 server II(ip:1.2.3.4)所以如果有这样的请求作为 www.mywebsite.com/images/123.jpg 我想将它们重定向到图像服务器(Server II)。

我希望包含 (.*jpg.*) 正则表达式的请求将重定向到 Server II

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

    <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> 
    

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

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

【问题讨论】:

  • 您能否提供图片来源和目标网址的示例?它将帮助我为您创建适当的规则
  • @VictorLeontyev 我希望当 url 包含 jpg 时,它将请求重定向到原始服务器。例如,如果我有:https://styleplace/UserFiles/Entities/TopBanners/top50161616_586.jpg
  • 并且可以通过这个网址在原始服务器中访问图像? :https://1.2.3.4/UserFiles/Entities/TopBanners/top50161616‌​_586.jpg
  • @VictorLeontyev 是的

标签: asp.net redirect iis


【解决方案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

【讨论】:

  • 到目前为止它不起作用,因为我发现我无权访问远程服务器,我尝试解决此问题并重试您的代码。
猜你喜欢
  • 2015-06-21
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 2019-01-15
  • 1970-01-01
相关资源
最近更新 更多