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>
相关推荐
Apache IoTDB2 天前
Apache IoTDB V2.0.3 发布|新增元数据导入导出脚本适配表模型功能
apache·iotdb
专注代码七年3 天前
php:5.6-apache Docker镜像中安装 gd mysqli 库 【亲测可用】
php·apache
不会c嘎嘎4 天前
Linux --进度条小程序更新
linux·小程序·apache
IT成长日记4 天前
【Doris基础】Doris中的Tablet详解:核心存储单元的设计与实现
apache·doris·tablet
学习HCIA的小白5 天前
Apache Airflow
apache
颯沓如流星5 天前
Apache Kafka 实现原理深度解析:生产、存储与消费全流程
分布式·kafka·apache
神秘的土鸡5 天前
Apache 高级配置实战:从连接保持到日志分析的完整指南
linux·运维·apache
GLAB-Mary5 天前
如何在 Ubuntu 24.04 服务器上安装 Apache Solr
ubuntu·apache·solr
Clownseven6 天前
网站缓存入门与实战:浏览器与Nginx/Apache服务器端缓存,让网站速度起飞!(2025)
nginx·缓存·apache
IT成长日记6 天前
【Doris基础】Apache Doris中FE和BE的职责详解
apache·doris·be·fe·职责