我的网站项目有 300 多个页面。随着时间的推移,我们创建了一个安全的新服务器。该服务器专门用于网站中的所有图像。
所以这是场景:
-
当前图像的实现(在 aspx 中,在 css 中)
http://www.mysite.com/assets/common/image1.jpg
-
有时在网页和CSS中它是这样指定的
~/assets/common/image1.jpg
-
想要使用这样的东西。
http://www.static.mysite.com/common/image1.jpg
-
以及安全页面
https://www.static.mysite.com/common/image1.jpg
正如你所看到的,所有图像都来自~/assets
文件夹但现在我想创建一个规则替换~/assets
with http://static.mysite.com
如何使用重写规则在 IIS 中实现此目的。
EXAMPLE:
ASPX
<img src="/assets/common/image1.jpg" id="ImageId1" alt="Image" width="100" height="100" />
<img src="http://mysite.com/assets/common/image2.jpg" id="ImageId2" alt="Image" width="100" height="100" />
想要有IIS规则,当找到上面的代码时,将其替换为http://static.mysite.com/common/image1.jpg http://static.mysite.com/common/image1.jpg
<img src="http://static.mysite.com/common/image1.jpg" id="ImageId1" alt="Image" width="100" height="100" />
<img src="http://static.mysite.com/common/image2.jpg" id="ImageId2" alt="Image" width="100" height="100" />
您需要在 IIS 中创建出站规则。规则将需要以下内容:
- 前提条件应该只检查html文件(我使用默认的IsHTML)
- 在“匹配内容”中,选择您要检查链接的元素
- 模式是
^(.*)/assets/(.*)
- 动作属性是http://static.mysite.com/ http://static.mysite.com/{答:2}。 R:2 指的是上面正则表达式中的第二个()。单击“测试模式”按钮后,您可以检查您需要的内容。
下面是满足上述条件的简单规则:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)