做網站的朋友一般都會遇到這樣的一種情況,就是別人的網站經常會調用我們自己網站的圖片或者文件,這無形之中會增加我們的服務器的壓力,尤其是對于一些服務器帶寬并不是十分富裕的網站來說就更是雪上加霜。因此我們需要學會設置防盜鏈來應對或者說來杜絕這樣的情況發生。今天361源碼就從IIS和Apache環境來分別教大家如何設置防盜鏈。
一、apache和iis6實現防盜鏈規則相同,在isapi篩選器開啟自定義url靜態化支持(一般的虛擬主機商都會提供),然后進入httpd.conf中,復制以下代碼加進去:
RewriteEngine onRewriteCond %{HTTP_REFERER} !baidu.com [NC]RewriteCond %{HTTP_REFERER} !google.com [NC]RewriteCond %{HTTP_REFERER} !xxx.com [NC]RewriteRule .*/.(gif|jpg)$ /band.txt [NC,L]
簡單介紹一下:
Tips:xxx.com是您自己的域名,band.txt是被盜鏈后的提示內容文件。
二、iis7實現防盜鏈則需要修改web.config文件,復制以下代碼保存即可:
<?xml version="1.0" ?><configuration> <system.webServer> <rewrite> <rules> <rule name="Prevent hotlinking"> <match url="^.*/.(rar|zip|jpg|gif)$" ignoreCase="true" /> <conditions> <add input="{HTTP_REFERER}" pattern="http://www.xxxxxx.com/.*" negate="true" /> <add input="{HTTP_REFERER}" pattern="http://xxxxxx.com/.*" negate="true" /> </conditions> <action type="Rewrite" url="404.html" /> </rule> </rules> </rewrite> </system.webServer></configuration>
OK,完成!
新聞熱點
疑難解答
圖片精選