Urlrewrite重写模块配置文件web.config代码如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <directoryBrowse enabled="true" /> <rewrite> <rules> <rule name="fz" stopProcessing="true"> <match url=".*.(jpg|jpeg|gif|png|bmp|zip|rar|exe|7z|iso|mp3|avi|mp4|mkv|php)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_REFERER}" pattern="sgtfz.cn" negate="true" /> <add input="{HTTP_REFERER}" pattern="www.sgtfz.cn″ negate="true" /> </conditions> <action type="Redirect" url="http://xxx.cn/" redirectType="Found" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
用法:
<add input="{HTTP_REFERER}" pattern="sgtfz.cn" negate="true" /> <add input="{HTTP_REFERER}" pattern="www.sgtfz.cn″ negate="true" />
上面这两行代码是,只允许sgtfz.cn和www.sgtfz.cn这两个站点连接。
<match url=".*.(jpg|jpeg|gif|png|bmp|zip|rar|exe|7z|iso|mp3|avi|mp4|mkv|php)$" />
上面这行代码是禁止括号中的后缀名文件被盗用,重写为下面那行代码url=”http://xxx.cn/”的网址。
<action type="Redirect" url="http://xxx.cn/" redirectType="Found" />
重写后这个可以是网址http://xxx.cn/也可以是图片或其它内容http://xxx.cn/xx_img.jpg