Apache server uses .htaccess file to set anti-theft chain

  

One problem that users often face is the server traffic problem, and the site file is the most important part of the chain. The so-called chain stealing refers to the direct linking of other websites to the files on our website. Generally speaking, the objects of the chain are mostly large-volume files with large bandwidth, such as pictures and videos. The main consequences of this are: increased traffic load on the server, affecting the access speed of our website.

If you are using an Apache server, you can easily set it up using .htaccess files to prevent users at other sites from stealing files from our site.

Using .htaccess to ban chaining

Using .htaccess to prevent websites such as images, compressed files, or videos from being stolen by non-Html files is quite simple, by adding them to the file. A few sentences can protect our precious bandwidth. For example, the settings of this site are as follows:

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$ [NC]

RewriteCond %{HTTP_REFERER} !sudu.cn [NC]

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

RewriteCond %{HTTP_REFERER} !Google.cn [NC]

RewriteCond %{HTTP_REFERER} !bloglines. Com [NC]

RewriteCond %{HTTP_REFERER} !feedburner.com [NC]

RewriteCond %{HTTP_REFERER} !feedsky.com [NC]

RewriteRule .*\\ .(gif| Jpg)$http://sudu.cn/no.png [R,NC,L]

Explain the above statement briefly:

1. RewriteCond %{HTTP_REFERER} !^$ [NC]

Allows access to "HTTP_REFERER", which allows the user to enter the image file directly when entering the image address in the browser address bar. In general, this is optional, but it is recommended that if you force it to have "HTTP_REFERER" to access it, it may cause problems, such as when a user accesses through a proxy server.

2, RewriteCond %{HTTP_REFERER} !45it.net [NC]

Set the HTTP source to allow access, including our site itself, Google, Baidu, Bloglines, Feedburner, etc.

3, RewriteRule .*\\.(gif| Jpg| Png)$ http://45it.net/no.png [R,NC,L]

Define the image to be replaced when the chain is stolen, and let all the pages that hack the jpg, gif, png, etc. Display the no.png file in the root directory. Note: Do not replace the displayed image in the directory where the anti-theft chain is set, and the smaller the image file size, the better. Of course, you can also use the following statement instead of setting a replacement image:

RewriteRule .*\\.(gif| Jpg| Png)$ – [F]

4. Explain that R, NC, and L

R is the meaning of steering

NC refers to case insensitivity

The role of L is to indicate the end of this turn, the subsequent turn is not affected by the previous judgment statement

5, to prevent the file type of the chain

In the middle is gif, jpg, png, and other file types can be changed or added as needed, such as rar, mov, etc., use between different file extensions “| & rdquo; segmentation.

In this case, you can basically prevent theft of the stolen chain, and you can minimize the fearless consumption of server traffic.

Copyright © Windows knowledge All Rights Reserved