Hotlink Protection Configuration for Independent IP Hosts (Applicable to VPS Cloud Host Servers)
Published: 2011-09-23
apache hotlink protection:
Add to the .htaccess file
RewriteEngine on
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !xxx.net [NC]
RewriteRule .*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$ /band.txt [NC,L]
iis6 hotlink protection:
If our company's assistant environment is installed, please first follow http://www.west.cn/faq/list.asp?unid=650 to enable the pseudo-static component.
If it is a clean version system, please follow http://www.west.cn/faq/list.asp?unid=639 to enable the pseudo-static component.
Then configure according to the following system rules in the configuration file.
Go to others/httpd.conf, keep the first two lines, copy the following rules and save them.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !xxx.net [NC]
RewriteRule .*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$ /band.txt [NC,L]
xxx.net is your own domain.
band.txt is the file containing the message displayed after hotlinking is detected.
iis7+ hotlink protection:
Implemented using the url-rewrite module. Module download address https://www.iis.net/downloads/microsoft/url-rewrite
Create a web.config file in the website root directory wwwroot, copy the following code and save it. If the website has pseudo-static settings and web.config already exists, only copy the code in the middle colored part and add it after the first <rules>.
<?xml version="1.0" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Prevent hotlinking">
<match url="^.*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$" ignoreCase="true" />
<conditions>
<add input="{HTTP_REFERER}" pattern="http://www.xxxxxx.com/.*" negate="true" />
<add input="{HTTP_REFERER}" pattern="http://xxxxxx.com/.*" negate="true" />
</conditions>
<action type="Rewrite" url="/404.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
nginx hotlink protection:
Refer to adding a location configuration for static files.
server {
listen 80;
server_name www.yoursite.com;
# Match images and other static resources
location ~ .*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$
{
expires 30d;
access_log /dev/null;
valid_referers *.yoursite.com yoursite.com;
if ($invalid_referer){
return 444;
}
}
}
Related products: Abnormal Traffic Scrubbing Service Product Introduction
```