Skip to content


apache下rewrite防盗链

在http.conf中添加模块

LoadModule rewrite_module modules/mod_rewrite.so
#可能需要的其它相关模块
LoadModule mime_module modules/mod_mime.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule headers_module modules/mod_headers.so

rewrite方式
可以自定的我内容,如显示友好的图片
可以地址中带URL进行破解
充许空referer
在根目录下新建allow目录存放允许访问的内容,如leech.gif
——————————-

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/allow
RewriteRule ^.*$ – [L]
RewriteCond %{REQUEST_FILENAME} \.(gif|jpg|jpeg|png|swf|css|rar|zip)$ [NC]
RewriteCond %{HTTP_REFERER} !^$ [NC] #空referer
RewriteCond %{HTTP_REFERER} !192.168.1.111 [NC]
RewriteCond %{HTTP_REFERER} !192.168.1.221 [NC]
RewriteCond %{HTTP_REFERER} !domain\.com [NC]
RewriteCond %{HTTP_REFERER} !domain\.net [NC]
RewriteCond %{HTTP_REFERER} !anotherdomain\.com [NC]
RewriteRule (.*) /allow/leech.gif [R,NC,L]

SetEnv方式
直接转到403页面去,如果请求是图片的话,那就是一个红X
————————-


SetEnvIfNoCase Referer “^http://192.168.1.111″/ local_ref=1
SetEnvIfNoCase Referer “^http://192.168.1.221″/ local_ref=1
SetEnvIfNoCase Referer “^http://.*\.domain\.com” local_ref=1
SetEnvIfNoCase Referer “.*\.domain\.com” local_ref=1
SetEnvIfNoCase Referer “^http://domain.com”/ local_ref=1
SetEnvIfNoCase Referer “^http://*\.domain\.net” local_ref=1
SetEnvIfNoCase Referer “.*\.domain\.net” local_ref=1
SetEnvIfNoCase Referer “^http://domain\.net”/ local_ref=1
SetEnvIfNoCase Referer “^http://*\.anotherdomain\.com” local_ref=1
SetEnvIfNoCase Referer “.*\.anotherdomain\.com” local_ref=1


SetEnv NoLOG 1
Order Allow,Deny
Allow from env=local_ref

参考
http://blogsdiy.org/2007-04/prevent-hotlinking/

Posted in Apache, 技术.

Tagged with , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.