网站防盗链的设置方法(Apache与IIS)
网站建设 2022-07-27 09:12www.1681989.com免费网站
很多时候,有的网站会引用我们网站上的图片或者其他文件,这样无形会增加我们服务器的带宽,所以此时我们需要设置下防盗链来杜绝这种情况发生,余斗分别就apache与IIS环境教大家 […]
RewriteEnge on
RewriteCond %{HTTP_REFERER} !baidu. [NC]
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !xxx. [NC]
RewriteRule .\.(gif|jpg)$/band.txt [NC,L]
<?xml version="1.0" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Prevent hotlkg">
<match url="^.\.(rar|zip|jpg|gif)$" ignoreCase="true"/>
<conditions>
<add put="{HTTP_REFERER}" pattern="http://.xxxxxx./." negate="true"/>
<add put="{HTTP_REFERER}" pattern="http://xxxxxx./." negate="true"/>
</conditions>
<action type="Rewrite" url="/404.html"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
很多时候,有的网站会引用我们网站上的图片或者其他文件,这样无形会增加我们服务器的带宽,所以此时我们需要设置下防盗链来杜绝这种情况发生,余斗分别就apache与IIS环境教大家如何设置防盗链
apache和iis6实现防盗链规则相同,在isapi筛选器开启自定义url静态化支持(一般的虚拟主机商都会提供),然后进入httpd.conf中,复制推火网以下代码加进去
RewriteEnge on
RewriteCond %{HTTP_REFERER} !baidu. [NC]
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !xxx. [NC]
RewriteRule .\.(gif|jpg)$/band.txt [NC,L]
Tips:xxx.是您自己的域名,band.txt是被盗链后的提示内容文件。
iis7实现防盗链则需要修改web.config文件,复制推火网以下代码保存即可
<?xml version="1.0" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Prevent hotlkg">
<match url="^.\.(rar|zip|jpg|gif)$" ignoreCase="true"/>
<conditions>
<add put="{HTTP_REFERER}" pattern="http://.xxxxxx./." negate="true"/>
<add put="{HTTP_REFERER}" pattern="http://xxxxxx./." negate="true"/>
</conditions>
<action type="Rewrite" url="/404.html"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>