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>
相关推荐
行业研究员4 天前
腾讯位置服务核心功能与应用场景解析
apache·lbs·腾讯位置服务
SeaTunnel5 天前
Apache SeaTunnel 提交一个任务都经过了什么?
java·大数据·服务器·apache·etl·seatunnel
SelectDB8 天前
基于 Apache Doris 搭建 RAG 系统:从基础 RAG 到知识图谱增强的完整实现与选型指南
apache
SelectDB8 天前
SelectDB Enterprise 4.0.5:企业级实时分析与 AI 数据底座怎么选?安全合规配置指南
apache
隔窗听雨眠8 天前
80TB电商数据迁移实录:从PostgreSQL分析困境到Apache Doris架构突围
postgresql·架构·apache
lsh曙光9 天前
Apache服务
apache
Norris Huang10 天前
Icevue:为 Apache Iceberg REST Catalog 打造一个轻量、只读的可视化入口
apache
ajassi200011 天前
AI语音智能体开发日记(三)解决小程序配网中的蓝牙命名与MAC地址获取问题
ai·apache·ai编程
SelectDB技术团队11 天前
当 PostgreSQL 面临性能瓶颈:80TB 电商业务迁移至 Apache Doris 的实践思考
数据库·postgresql·apache
sbjdhjd11 天前
安全初级 | Upload 文件上传漏洞实操
android·经验分享·安全·网络安全·开源·php·apache