Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize the hotlink protection technology of Apache

Shulou Source: shulou.com Published: 2022-06-01 13:03:36 10月02日 Update

This article mainly introduces "how to realize the technology of hotlink protection of Apache". In the daily operation, I believe that many people have doubts about how to realize the technology of hotlink protection of Apache. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to realize the technology of hotlink protection of Apache". Next, please follow the editor to study!

The implementation method of Apache hotlink protection can be implemented with rewrite. First of all, make sure that the rewrite module of Apache is available: if you can control the Apache httpd.conf file, open httpd.conf and make sure you have this line of configuration:

The copy code is as follows:

LoadModule rewrite_module modules/mod_rewrite.so

Then, where you find the configuration for your website, add the following code:

The copy code is as follows:

ServerName jb51.net

# hotlink protection configuration

RewriteEngine On

RewriteCond% {HTTP_REFERER}! ^ http://jb51.net/.*$ [NC]

RewriteCond% {HTTP_REFERER}! ^ http://jb51.net$ [NC]

RewriteCond% {HTTP_REFERER}! ^ / / www.iis7.com/.*$ [NC]

RewriteCond% {HTTP_REFERER}! ^ / / www.iis7.com$ [NC]

RewriteRule. *\. (gif | jpg | swf) $/ / www.iis7.com/about/nolink.png [RMagneNC]

Hotlink protection configuration description: the red part: indicates their own trust site. For my site, set to http://www.xiaohui.com and http://xiaohui.com

Green: the extension of the file to be protected (to | separate). Files with these extensions must be referenced by a red URL before they can be accessed.

The blue part: the redirected page after the hotlink. To output warning messages, this picture should be as small as possible. For example, my warning picture is / 2018img/2018/09/15143940.png. For simple reasons, in my green font section, there is no .png image in the image extension I want to protect, while the warning picture is .png. (there are no other pictures of .png in my site)

Then restart the apache server.

Some users are using virtual hosts and cannot modify httpd.conf files or restart the server without control of the server. Then make sure that your virtual host supports .htaccess, write the above configuration to the .htaccess http://www.bbqmw.net/ file, and put it in the root directory or the directory where the image is located:

The copy code is as follows:

The contents of the .htaccess file:

# hotlink protection configuration

RewriteEngine On

RewriteCond% {HTTP_REFERER}! ^ http://jb51.net/.*$ [NC]

RewriteCond% {HTTP_REFERER}! ^ http://jb51.net$ [NC]

RewriteCond% {HTTP_REFERER}! ^ / / www.iis7.com/.*$ [NC]

RewriteCond% {HTTP_REFERER}! ^ / / www.iis7.com$ [NC]

RewriteRule. *\. (gif | jpg | swf) $/ / www.iis7.com/about/nolink.png [RMagneNC]

Note:

1. The configuration in the httpd.conf file is read once when apache is started, so it is very efficient.

2. The configuration in the htaccess file needs to be read and analyzed every time it is accessed, so it is very inefficient.

At this point, the study on "how to realize the technology of hotlink protection in Apache" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Anti-theft file configuration code picture technology parts learning server service alert host extension efficiency method more site red green website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Shulou Technology OPPO Reno Shulou Tech Info