LY’Blog~~blog.ly5.org~~ Rotating Header Image

简单使用.htaccess防止图片盗链

Simple Hotlinking in Apache 一个简单的使用Apache的.htaccess禁用其它网站调用站点的图片,并可以设置允许调用的站点。

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?google\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?bloglines\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} !hotlink.png$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://mysite.com/img/hotlink.png [L]

上面的正则判断允许mysite.com、google.com、bloglines.com这三个网站访问站点的图片。

0 Comments on “简单使用.htaccess防止图片盗链”

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word