apache、iis6、ii7独立ip主机设置防盗链(适用vps云主机服务器)

  1. 若是安装了我司助手环境请先按http://faq.myhostadmin.net/faq/listagent.asp?unid=650 把伪静态组件开启

  2. 若是纯净版系统,请按http://faq.myhostadmin.net/faq/listagent.asp?unid=639 把伪静态组件开启

    然后在配置文件中按以下系统规则配置


apache和iis6实现防盗链规则相同:


进入others/httpd.conf中,保留前两行,复制以下规则保存即可

RewriteEngine on 

RewriteCond %{HTTP_REFERER} !baidu.com [NC]

RewriteCond %{HTTP_REFERER} !google.com [NC]

RewriteCond %{HTTP_REFERER} !xxx.net [NC]

RewriteCond %{HTTP_REFERER} !^$ [NC]

RewriteRule .*\.(gif|jpg)$ /band.txt [NC,L]


xxx.net是您自己的域名

band.txt是被盗链后的提示内容文件


iis7实现防盗链:


在网站根目录wwwroot下创建一个web.config文件,复制以下代码保存即可, 如果网站有设置伪静态,已存在web.config,则只复制中间颜色部分代码,加到第一个<rules>之后即可

<?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" /> 

       <add input="{HTTP_REFERER}" pattern="^$" negate="true" />

      </conditions>  

     <action type="Rewrite" url="/404.html" />  

    </rule>

   </rules>  
  </rewrite>  
 </system.webServer> 
</configuration>




日期:2011-09-23

打印 】