这是我一直在苦苦挣扎的问题
我在服务器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 。
使用Url重写我添加了一条规则:
{{1}}
如您所见,它会将请求重写为静态图像,如何定义它以转到 1.2.3.4/images/imagename.jpg ?
最好的解决方案是,如果我可以通过我的主机文件忽略包含 jpg 的请求,是否有办法实现?
答案 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.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