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>