鉴于图片外链对主机的压力,不得不做下防盗链的措施杜绝这种现象,看看网易、百度的博客空间,粘贴图片到其它网站,所有图片只显示xx图册字样,一看就知道是做了防盗链图片设置。
考虑性能音响问题,介绍一下.htaccess来做防盗链的方法。
通过修改.htaccess文件可以自由添加允许显示图片的网站,这是为了保证搜索引擎的访问,需要把它们也加入进来,其它访问者带盗链的图片会直接显示你设置的跳转图片。
.htaccess文件如下,如果已经开启rewrite模块根据实际去掉重复字段。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp-content/uploads/
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
RewriteCond %{HTTP_REFERER} !xianguo.com [NC]
RewriteCond %{HTTP_REFERER} !feedburner.com [NC]
RewriteCond %{HTTP_REFERER} !feedsky.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !google.com.hk [NC]
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
RewriteCond %{HTTP_REFERER} !so.com [NC]
RewriteCond %{HTTP_REFERER} !soso.com [NC]
RewriteCond %{HTTP_REFERER} !sougou.com [NC]
RewriteCond %{HTTP_REFERER} !yahoo.com [NC]
RewriteCond %{HTTP_REFERER} !youdao.com [NC]
RewriteCond %{HTTP_REFERER} !bing.com [NC]
RewriteRule .*.(gif|jpg|jpeg|png|bmp|zip|rar|swf)$ http://www.baidu.com/img/bdlogo.png [R,NC,L]
</IfModule>
好吧,我把盗链图片全转向百度的logo去了。
附上实际使用的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]RewriteBase /wp-content/uploads/
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
RewriteCond %{HTTP_REFERER} !xianguo.com [NC]
RewriteCond %{HTTP_REFERER} !feedburner.com [NC]
RewriteCond %{HTTP_REFERER} !feedsky.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !google.com.hk [NC]
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
RewriteCond %{HTTP_REFERER} !so.com [NC]
RewriteCond %{HTTP_REFERER} !soso.com [NC]
RewriteCond %{HTTP_REFERER} !sougou.com [NC]
RewriteCond %{HTTP_REFERER} !yahoo.com [NC]
RewriteCond %{HTTP_REFERER} !youdao.com [NC]
RewriteCond %{HTTP_REFERER} !bing.com [NC]
RewriteRule .*.(gif|jpg|jpeg|png|bmp|zip|rar|swf)$ http://www.baidu.com/img/bdlogo.png [R,NC,L]
</IfModule>
No comments:
Post a Comment