Apache anti-theft chain summary
Apache anti-theft chain of the first implementation method, can be implemented with rewrite.
I. Encounter Picture hotlinking
Domestic web site Hotlinking Wind, the most unfortunate is that we use a paid host with traffic restrictions of the individual. No way, had to add a simple anti-hotlinking (Anti-leech) measures. My server is Apache, handling anti-theft chain is relatively simple. also welcome you to the younger brother's forum, memory fragments www.debris.cn, I hope you have a lot of guidance!
Two. Using rewrite technology to implement Apache anti-theft chain (refused to jump to the specified page)
Apache anti-theft chain of the first implementation method, can be implemented with rewrite. The first thing to confirm is that Apache's rewrite module is available: You can control the Apache httpd.conf file, open httpd.conf, and make sure there's a line configured:
The code is as follows:
LoadModule rewrite_module modules/mod_rewrite.so
Then add the following code where you find the appropriate configuration for your site:
The code is as follows:
ServerName debris.cn
# Anti-theft chain configuration
Rewriteengine on
Rewritecond%{http_referer}!^http://debris.cn/.*$ [NC]
Rewritecond%{http_referer}!^http://debris.cn$ [NC]
Rewritecond%{http_referer}!^http://www. debris.cn /.*$ [NC]
Rewritecond%{http_referer}!^http://www. debris.cn $ [NC]
Rewriterule. *\. (gif|jpg|swf)$ http://www. debris.cn/about/nolink.png [R,NC]
description of the anti-theft chain configuration :
Red Section : Represents your own trust site. For my site, it's set to http://www. debris.cn and/httpdebris.cn
Green Section : To protect the file's extension (separated by |). Files with these extensions must be referenced in a red-labeled URL before they can be accessed.
Blue Section : redirect page after hotlinking. To output the warning message, this picture should be as small as possible. For the sake of simple processing, my green font section, to protect the picture extension, does not have a. png picture, and the warning picture is. png.
Then restart the Apache server.
Some users are using a virtual host that does not have control over the server and cannot modify the httpd.conf file and restart the server. Then please confirm your virtual host support . htaccess, write the above configuration to the. htaccess file, and put it in the directory where the root or picture is located:
The code is as follows:
Contents of the. htaccess file:
# Anti-theft chain configuration
Rewriteengine on
Rewritecond%{http_referer}!^http://debris.cn/.*$ [NC]
Rewritecond%{http_referer}!^http://debris.cn[NC]
Rewritecond%{http_referer}!^http://www.debris.cn*$ [NC]
Rewritecond%{http_referer}!^http://www.debris.cn$ [NC]
Rewriterule. *\. (gif|jpg|swf) $ http://www.debris.cn/about/nolink.png [R,NC]
Note:
1, httpd.conf files in the configuration, is the Apache boot time read, high efficiency
2. The configuration in the. htaccess file requires read analysis for each visit and is inefficient.
Three. Using Setenvifnocase and access technology to implement Apache anti-theft chain (direct rejection)
Another way is to take advantage of setenvifnocase and access. The specific code is as follows:
The code is as follows:
setenvifnocase Referer "^http://debris.cn " local_ref=1 
setenvifnocase Referer" ^http://www.< Span style= "text-align:left;font-family: ' Microsoft Jas Black '; font-size:14px;font-style:normal;font-weight:normal; Background-color:rgb (255,255,255); " >&NBSP;
order allow,deny&NBSP;
allow from Env=local_ref&NBSP;
Put the above code in the previous httpd.conf or. htaccess file.
Four. Apache anti-theft chain technology Summary
By judging the value of the Referer variable, judging whether the reference of the picture or resource is lawful, only the Referer within the set range can access the specified resources, thus realizing the purpose of the anti-theft chain (Anti-leech). It should be noted that not all user agents (browsers) will set the Referer variable, and some can also manually modify the Referer, that is, referer can be forged. What this article is talking about is just a simple means of protection. Of course, it is enough to cope with the hotlinking of the general.
Welcome to the memory fragment www.debris.cn, looking for your memory in fragments!
This article is from the "Debris Memory" blog, please be sure to keep this source http://debris.blog.51cto.com/1614432/1640770
Apache anti-theft chain summary