IIS 7.5使用IP地址将某些请求重定向到其他服务器
这是我苦苦挣扎了一段时间的问题.
我在服务器I 中托管了一个地址为 www.mywebsite.com
的网站,但该网站的图像来自服务器II (IP:1.2.3.4),因此,如果有诸如 www.mywebsite.com/images/123.jpg 之类的请求,我想将它们重定向到图像服务器(服务器II ).
Here is a problem I have been struggling with for a while.
I host a website with the address www.mywebsite.com
in server I but the images of the site come from server II (ip: 1.2.3.4) so if there are requests such as www.mywebsite.com/images/123.jpg I would like to redirect them to the image server(Server II).
我希望包含(.* jpg.*)
正则表达式的请求将重定向到服务器II .
I would like that requests that contain (.*jpg.*)
regex will redirect to Server II.
-
使用Url重写,我添加了一条规则:
Using Url rewrite I added a rule:
<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 ?
It rewrites the request to a static image as you can see, how can I define it to go to 1.2.3.4/images/imagename.jpg?
最好的解决方案是,如果我只能通过宿主文件忽略包含 jpg 的请求,有办法吗?
The best solution would be if I could just ignore requests containing jpg via my host file, is there a way to that?
您重定向的规则应如下所示:
You redirect rule should be like that:
<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域例如:
It will redirect all requests to files with .jpg
extension to 1.2.3.4 domain
For example:
http://www.mywebsite.com/dog-1210559_960_720.jpg
到 http://1.2.3.4/dog-1210559_960_720.jpg
http://www.mywebsite.com/UserFiles/Entities/TopBanners/top50161616_586.jpg
至 http://1.2.3.4/UserFiles/Entities/TopBanners/top50161616_586.jpg