Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set Rewrite hotlink protection in apache

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to set up Rewrite hotlink protection in apache. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Set .htaccess to prohibit picture piracy

RewriteEngine on

Open and rewrite url

RewriteCond% {REQUEST_URI}! ^ / allow/.*$

Excluded url. This is quite important because these are filtered later in the referer filter. So open this can "steal the chain", so that users can correctly display the wrong site.

RewriteCond% {REQUEST_FILENAME}\. (gif | jpeg | png | jpg) $[NC]

The above is to determine whether it is a picture file: you can also set more file types according to your needs. Or it could be exe or something.

RewriteCond {HTTP_REFERER}! ^ $

The above line is intended to allow empty "HTTP_REFERER" access, that is, the display of the image file when the user is allowed to enter the image address directly in the browser address bar. It is recommended that if you are forced to have "HTTP_REFERER" to access, it may cause some problems, such as entering the address directly in the url address bar.

RewriteCond% {HTTP_REFERER}! php-oa\ .org [NC]

RewriteCond% {HTTP_REFERER}! google\ .com [NC]

RewriteCond% {HTTP_REFERER}! baidu\ .com [NC]

Set the HTTP sources allowed to access, including the site itself, Google, Baidu, and so on.

RewriteRule (. *) / allow/error.gif [Renew301 NC Magi L]

Redirect access that does not meet the referer condition to error.gif. Have you found that error.gif is located in the directory allow that allows "theft chain"? be careful, otherwise, warnings and pictures will not be displayed on each other's website.

As above, the function we want has been realized. Not only block / prohibit access to non-website hotlinks, but also transfer hotlink requests to their own websites to let readers know who is the real publisher (photo source site).

Hotlink protection settings for other types of files

If there are other similar large and bandwidth-consuming files on your website, such as flash and mp3, which are hacked by other websites, you can also adopt the above strategy. For example, for Flash files, you can use settings similar to the following:

RewriteCond% {REQUEST_URI} ^ / allow

RewriteCond% {REQUEST_FILENAME}\ .swf$ [NC]

RewriteCond {HTTP_REFERER}! ^ $

RewriteCond% {HTTP_REFERER}! php-oa\ .org [NC]

RewriteRule (. *) / allow/error.swf [Renew301 NC Magi L]

Of course, you need a flash file "error.swf" that declares copyright information in advance. Other hotlink settings such as mp3 files, compressed files (zip or rar) are the same as this.

The above is how to set up Rewrite hotlink protection in apache. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 258

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report