伪静态apache、iis规则设置防盗链

[复制链接]
查看1381 | 回复0 | 2022-3-17 08:53 | 显示全部楼层 |阅读模式
伪静态apache、iis规则设置防盗链
Linux下规则文件.htaccess(手工创建.htaccess文件到站点根目录)
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteCond %{HTTP_REFERER} !baidu.com [NC]
  4. RewriteCond %{HTTP_REFERER} !google.com [NC]
  5. RewriteCond %{HTTP_REFERER} !xxx.net [NC]
  6. #RewriteCond %{HTTP_REFERER} !^$ [NC]
  7. RewriteRule .*\.(gif|jpg|png|css|js)$ /band.txt [NC,L]
  8. </IfModule>
复制代码

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


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

  1. <?xml version="1.0" ?>
  2. <configuration>
  3.   <system.webServer>  
  4.    <rewrite>  
  5.     <rules>   
  6.       <rule name="rule1" stopProcessing="true">
  7.         <match url="^.*\.(css|js|gif|png|jpg|jpeg)$" ignoreCase="true" />
  8.         <conditions>
  9.           <add input="{HTTP_REFERER}" pattern="您的域名.com(不用加www)" negate="true" />
  10.           <!--<add input="{HTTP_REFERER}" pattern="^$" negate="true" />-->
  11.         </conditions>
  12.        <action type="AbortRequest" />
  13.       </rule>
  14.    </rules>  
  15.   </rewrite>  
  16. </system.webServer>
  17. </configuration>
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-4-16