iis httpd.ini IIS pictures to prevent hotlinking

  • 2020-05-09 19:38:03
  • OfStack

1. Create directory e:Rewrite

Upload the four files under Rewrite (httpd.ini, httpd.parse.errors, mtbnotif.dll, Rewrite.dll) here.

2. Set IIS property, select website property, go to ISAPI filter,

Close the properties dialog.

To view the site properties again, go to the ISAPI filter

If you see a green arrow with an upward state, the Rewrite module has been installed successfully.

Click add, enter rewrite in the name, and the executable file will select Rewrite.dll, and click ok. And just to be sure,

3. Modify e: the httpd.ini file in Rewrite is as follows


[ISAPI_Rewrite] 


# Protect httpd.ini and httpd.parse.errors files 
# from accessing through HTTP 

# Discuz4.10 Rewrite The rules  


RewriteCond Host: (.+) 
# RewriteCond Referer: (?!http://1.*).* 
RewriteCond Referer: (?!http://(?:*.abc.net|*.google.com|*.baidu.com)).+ 

RewriteRule .*.(?:gif|jpg|png|exe|rar|zip) /block.gif [I,O,N] 



The above rule is *.abc.net's site google baidu is not blocked


To ensure that httpd.ini has writable permissions, set isapi_rewrite installation folder everyone to have modifier permissions and remove the file's read-only property.

The default Settings of httpd.ini are as follows:


RewriteCond Host: (.+)
RewriteCond Referer: (?!http://\1.*).*

Let's add a sentence to it


RewriteRule .*\.(?:gif|jpg|png|exe|rar|zip) /block.gif [I,O]

Can be realized gif/jpg/png/exe/rar/zip files hotlinking prevention, hotlinking page shows the/block gif. block. gif is a small image file, we can type our own website copyright logo and anti-hotlinking declaration on it.

If you follow the above Settings, all websites except this site cannot use the images here. What if you want to allow 1 exception sites such as google,baidu and other 1 non-profit website to reference? We can do this with the following regular expression


RewriteCond Referer: (?!http://(?:www\.jb51\.net|www\.google\.com|www\.baidu\.com)).+

If you want to allow all google shape and baidu stand as images. baidu. com, images. google. com setting station are as follows:


RewriteCond Referer: (?!http://(?:*\.jb51\.net|*\.google\.com|*\.baidu\.com)).+

So far, a fairly effective anti-hotlinking system has come out, but there is a problem with the above Settings. If the viewer browns the hotlinking page and visits the site page, the image cache of hotlinking will affect the normal display of the image. the



RewriteRule .*\.(?:gif|jpg|png|exe|rar|zip) /block.gif [I,O]
 Instead of 
RewriteRule .*\.(?:gif|jpg|png|exe|rar|zip) /block.gif [I,O,N]

The parameter N means to re-request the file from the site instead of reading it from the local cache.


Related articles: