First explain the image hotlink protection and redirection:
What is the use of image hotlink protection?
Prevent other websites from stealing your images and wasting your precious traffic.
What is the use of image redirection?
If your website is mainly based on images, and one day you find that the traffic is almost used up before the end of the month, then you can use image redirection to redirect image download requests to other spaces (such as trial hosts) without modifying the web page. ), temporary transition.
Let’s start with the explanation. For example, if your pictures are in the img directory, then put a file named .htaccess in that directory with the following content:
-
- RewriteEngine on
-
- !zhuaxia.com [NC]
-
- RewriteCond %{HTTP_REFERER} !google.com [NC]
-
- RewriteCond %{HTTP_REFERER} !baidu.com [NC]
-
- RewriteCond %{HTTP_REFERER} !bloglines.com [NC]
-
- RewriteRule .(jpg|gif|png |bmp|swf|jpeg) /image/replace.gif [R,NC,L]
-
- RewriteRule ^(.*)$ http://image.simcole.cn/image/$1 [L]
-
-
-
-
- Copy code
-
A rough explanation:
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !simcole.cn [NC]-
- RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
-
- RewriteCond %{HTTP_REFERER } !google.com [NC]
-
- RewriteCond %{HTTP_REFERER} !baidu.com [NC]
-
- RewriteCond %{HTTP_REFERER} !bloglines.com [NC]
-
-
-
-
- Copy code
-
This part is to determine whether the link is hotlinked. If the above conditions are true (that is, the request to access the image is neither directly entered in the URL, nor from simcole.cn, nor from zhuaxia.com, nor from google.com, nor from If it comes from baidu.com or not from bloglines.com), perform the following redirection:
RewriteRule .(jpg|gif|png|bmp|swf|jpeg) /image/replace.gif [R,NC,L] It means that all web pages that hotlink jpg, gif, png, bmp, swf, and jpeg files in the img directory will replace the displayed images with the replace.gif image in the image directory. Note that the replaced image should not be placed in the img directory where anti-hotlinking is set. If it is determined according to the above rules that the image request is not a hotlink, the following redirection will be executed:
RewriteRule ^(.*)$ http://image.simcole.cn/image/$1 [L] It means that all requests under the img directory will be redirected to the target server. For example, the original URL of a picture is http://img.it-home.org/data/attachment/forum/2016pic1/girl.jpg. Now it is It will go to http://img.it-home.org/data/attachment/forum/2016pic1/girl.jpg. Of course, you must first copy all the files in the img directory of the original server to the image directory of the temporary server before the redirection will be truly available. The effect is to save all the traffic occupied by downloading images from the original server and let the temporary server bear it.
Hotlinking, Apache |