通过IIS安装 URL 重写(URL Rewrite)模块,可以很方便的实施防盗链功能,下面我就介绍以下在 IIS 的各个版本使用 URL 重写(URL Rewrite)防盗链的方法。
IIS6防盗链功能
IIS6 需要安装一个第三方工具 ISAPI Rewrite 来实现 URL 重写,先安装 ISAPI_Rewrite3_0082.msi,安装完成后,在.htaccess 的文件里写入以下语句即可:
- RewriteCond Host:(.+)
- RewriteCond Referer:(?!http://\1.*).*
- RewriteRule.*\.(?:gif|jpg|png|exe|rar|zip)/block.gif[I,O]
IIS7/8防盗链功能
IIS7 以上不用安装第三方的软件,我们使用微软自己的 URL Rewrite 即可实现 URL 重写。
先安装 URL Rewrite 模块(点此下载),安装好后重启 IIS 管理器,然后点击当前主机,就会发现 URL 重写的图标了。
之后,编辑网站根目录下的 web.config 文件,将里面的内容修改为如下内容即可。
- <?xml version="1.0"encoding="UTF-8"?>
- <configuration>
- <system.webServer>
- <rewrite>
- <rules>
- <rule name="Prevent hotlinking">
- <match url="^.*\.(jpg|gif|css|js)$" ignoreCase="true"/>
- <conditions>
- <add input="{HTTP_REFERER}" pattern="https://www.williamlong.info" negate="true"/>
- </conditions>
- <action type="Rewrite" url="/images/block.jpg"/>
- </rule>
- </rules>
- </rewrite>
- </system.webServer>
- </configuration>
盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供其它服务提供商的服务内容,骗取最终用户的浏览和点击率。受益者不提供资源或提供很少的资源,而真正的服务提供商却得不到任何的收益。
CLOUD云计算