Home > CMS Tutorial > DEDECMS > body text

How does DEDECMS prevent pictures from being stolen?

藏色散人
Release: 2019-11-16 10:58:43
Original
1598 people have browsed it

How does DEDECMS prevent pictures from being stolen?

织梦DEDECMS如何防图片被盗链?

修改.htaccess

首先这种方法适合于用Apache来搭建服务器的用户,如果你使用IIS来搭建,这种方法不适用。 

推荐学习:dedecms教程

先解释一下图片防盗链和转向: 

图片防盗链有什么用? 

防止其它网站盗用你的图片,浪费你宝贵的流量。 

图片转向有什么用? 

如果你的网站以图片为主,哪天发现月底没到流量就快用光了,那就可以利用图片转向,在不修改网页的前提下,把图片下载请求转向到其它空间(比如试用主机),临时过渡。 

下面开始讲解,比如你的图片都在img目录下,那就在该目录下放一个名为 .htaccess 的文件,内容如下: 

RewriteEngine on  
RewriteCond %{HTTP_REFERER} !^$ [NC]  
RewriteCond %{HTTP_REFERER} !dedemao.com [NC]  
RewriteCond %{HTTP_REFERER} !google.com [NC]  
RewriteCond %{HTTP_REFERER} !baidu.com [NC]   
RewriteRule .(jpg|gif|png|bmp|swf|jpeg) /image/replace.gif [R,NC,L]  
RewriteRule ^(.*)$ http:\/\/www.dedemao.com\/image\/$1 [L]
Copy after login

大概解释下:

RewriteCond %{HTTP_REFERER} !^$ [NC] 
RewriteCond %{HTTP_REFERER} !dedemao.com [NC] 
RewriteCond %{HTTP_REFERER} !google.com [NC] 
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
Copy after login

这部分是判断是否盗链,如果以上条件都成立(即访问图片的请求,既不是直接输入网址,也不是来自dedemao.com,也不是来自google.com,也不是来自baidu.com的话),就执行下列转向:

 RewriteRule .(jpg|gif|png|bmp|swf|jpeg) /image/replace.gif [R,NC,L]
Copy after login


意思是让所有盗链 img 目录下 jpg、gif、png、bmp、swf、jpeg 文件的网页,显示的图片都用 image 目录下的 replace.gif 图片替换掉。注意替换显示的图片不要放在设置防盗链的 img 目录下。如果照上面的规则判断出图片请求不是盗链的,就执行以下转向:

RewriteRule ^(.*)$ http:\/\/www.dedemao.com\/image\/$1 [L]
Copy after login

 

意思是对 img 目录下所有的请求都转向到目标服务器,比如有个图片原来的 url 是 http://www.dedemao.com/img/girl.jpg ,现在就会转到 http://www.de.com/image/girl.jpg 去。当然了你得先把原服务器 img 目录下的文件统统拷贝到临时服务器的 image 目录下,转向才会真正可用。

The above is the detailed content of How does DEDECMS prevent pictures from being stolen?. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!