Home > php教程 > php手册 > 实用技巧 利用Apache实现禁止图片盗链

实用技巧 利用Apache实现禁止图片盗链

WBOY
Release: 2016-06-21 09:01:05
Original
809 people have browsed it

  1、假设充许连结图片的主机域名为:www.webjx.com

  2、修改httpd.conf

<ccid_code>SetEnvIfNoCase Referer "^http://www.webjx.com/" local_ref=1 <filesmatch> Order Allow,Deny Allow from env=local_ref </filesmatch></ccid_code>
Copy after login

这个简单的应用不光可以解决图片盗链的问题,稍加修改还可以防止任意文件盗链下载的问题。

使用以上的方法当从非指定的主机连结图片时,图片将无法显示,如果希望显示一张“禁止盗链”的图片,我们可以用mod_rewrite 来实现。

首先在安装 apache 时要加上 --enable-rewrite 参数加载 mod_rewrite 模组。

假设“禁止盗链”的图片为abc.gif,我们在 httpd.conf 中可以这样配置:

<ccid_code>RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?webjx.com /.*$ [NC] RewriteRule \.(gif|jpg)$ http://www.webjx.com/abc.gif [R,L]</ccid_code>
Copy after login



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template