rewrite2.0 设置防盗链,iis7.0+

IIS7.0可以通过URL rewrite模块实现防盗链,复制下面的代码,将zdzz.net改成你自己的域名然后保存为存为web.config,再将 web.config文件上传网站的根目录即可。如果已有web.config文件,只要将<rewrite>…</rewrite>这段代码添加到<system.webServer>和< /system.webServer>之间。

01 <?xml version="1.0" encoding="UTF-8"?>
02 <configuration>
03         <system.webServer>
04             <rewrite>
05                <rules>
06                  <rule name="Forbid image">
07                    <match url="\.(txt|doc|gif|jpg|jpeg|png|mp3|flv|swf)$" ignoreCase="false" />
08                       <conditions>
09                        <add input="{HTTP_REFERER}" pattern="^$" ignoreCase="false" negate="true" />
10                        <add input="{HTTP_REFERER}" pattern="^http://(www\.)?fenggefushi.com/.*$" negate="true" />
11                       </conditions>
12                     <action type="Rewrite" url="/wp-content/uploads/forbid.png" />
13                   </rule>
14                </rules>
15           </rewrite>
16      </system.webServer>
17  </configuration>

如果你想让盗链你的图片的网站上显示你准备的"禁止盗链“之类的图片,请将

 


1 <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />

换成


1 <action type="Rewrite" url="/images/nohotlinking.jpg" />

images/nohotlinking.jpg根据你实际的图片位置和名称做修改。

posted @ 2011-05-20 18:34  go on coding  阅读(585)  评论(1编辑  收藏  举报
悠季瑜伽会馆