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" ?> |
06 |
< rule name = "Forbid image" > |
07 |
< match url = "\.(txt|doc|gif|jpg|jpeg|png|mp3|flv|swf)$" ignoreCase = "false" /> |
09 |
< add input = "{HTTP_REFERER}" pattern = "^$" ignoreCase = "false" negate = "true" /> |
10 |
< add input = "{HTTP_REFERER}" pattern = "^http://(www\.)?fenggefushi.com/.*$" negate = "true" /> |
12 |
< action type = "Rewrite" url = "/wp-content/uploads/forbid.png" /> |
如果你想让盗链你的图片的网站上显示你准备的"禁止盗链“之类的图片,请将
1 |
< action type = "CustomResponse" statusCode = "403" statusReason = "Forbidden" statusDescription = "Forbidden" /> |
换成
1 |
< action type = "Rewrite" url = "/images/nohotlinking.jpg" /> |
images/nohotlinking.jpg根据你实际的图片位置和名称做修改。