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>
相关推荐
小宇的天下8 小时前
Cadence allegro---assign net
服务器·php·apache
软件派1 天前
Apache Paimon终极教程——流批一体存储引擎深度解析(附Flink集成案例+性能调优代码)
apache·性能调优·流批一体·实时数据处理·paimon教程·flink集成·湖仓架构
三水不滴1 天前
Apache RocketMQ的原理与实践
经验分享·apache·rocketmq
whale fall2 天前
celery -A tool.src.main worker --loglevel=info --queues=worker1_queue & 什么意思
python·学习·apache
TracyCoder1232 天前
ElasticSearch核心引擎Apache Lucene(五):相关性算分 (Scoring)
elasticsearch·apache·lucene
码上上班2 天前
一文学会apache httpd
apache
野生技术架构师2 天前
Spring Boot 3 集成 Apache Calcite:多数据源查询的终极解决方案
spring boot·后端·apache
TracyCoder1233 天前
ElasticSearch核心引擎Apache Lucene(四):段 (Segment) 的设计与合并
elasticsearch·apache·lucene
TracyCoder1233 天前
ElasticSearch核心引擎Apache Lucene(三):数值与空间数据索引
elasticsearch·apache·lucene
Elastic 中国社区官方博客3 天前
Elasticsearch:Apache Lucene 2025 年终总结
大数据·人工智能·elasticsearch·搜索引擎·apache·lucene