apache、iis规则设置防盗链

Linux下规则文件.htaccess(手工创建.htaccess文件到站点根目录)

复制代码
<IfModule mod_rewrite.c>
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|png|css|js|rar|zip|mp4|pdf)$ /band.txt [NC,L]
</IfModule>

注:xxx.net是您自己的域名,band.txt是被盗链后的提示内容文件

Windows2008、2012或更高系统下规则文件web.config (手工创建web.config文件到站点根目录)

复制代码
<?xml version="1.0" ?>
 <configuration>
  <system.webServer>  
   <rewrite>  
    <rules>   
      <rule name="rule1" stopProcessing="true">
        <match url="^.*\.(gif|jpg|png|css|js|rar|zip|mp4|pdf)$" ignoreCase="true" />
        <conditions logicalGrouping="MatchAny" >
          <add input="{HTTP_REFERER}" pattern="您的域名.com(不用加www)" negate="true" />
          <!--<add input="{HTTP_REFERER}" pattern="^$" />-->
        </conditions>
       <action type="AbortRequest" />
      </rule>
   </rules>  
  </rewrite>  
 </system.webServer> 
</configuration>
相关推荐
吧啦蹦吧2 小时前
org.apache.commons.beanutils.BeanUtils#populate
apache
java_logo1 天前
Apache IoTDB Docker 容器化部署指南:从入门到生产环境实践
docker·容器·apache·iotdb·iotdb部署教程·iotdb部署文档·docker部署iotdb
bluechips·zhao1 天前
中间件及框架漏洞详解(Nginx、Apache、Tomcat、Redis、Zookeeper、RabbitMQ、Kafka等)
nginx·web安全·网络安全·中间件·apache·网络攻击模型·java-rabbitmq
一个天蝎座 白勺 程序猿1 天前
Apache IoTDB(11):分段聚合深度解析——从原理到实战的完整指南
数据库·apache·iotdb
WZTTMoon2 天前
Apache Tomcat 体系结构深度解析
java·tomcat·apache
fiveym2 天前
Apache HTTP 服务搭建全攻略
网络协议·http·apache
知码者2 天前
对于Thinkphp5可能遇到的保存问题
服务器·php·apache·小程序开发·跨平台小程序
程序员老赵2 天前
Apache IoTDB Docker 容器化部署指南:从入门到生产环境实践
docker·apache
清平乐的技术专栏3 天前
Apache Superset可视化简介
apache
好学且牛逼的马3 天前
Apache Commons DbUtils
java·设计模式·apache