Thursday, June 5, 2014

[Apache][Security] A Hotlinking protection method

To block people display your image from another website and waste your bandwidth,
and also display a custom image as error message, you can use these code at your .htaccess:





1RewriteEngine On
2RewriteCond %{HTTP_REFERER} !^$
3RewriteCond %{HTTP_REFERER} !^http://(www\.)?naturefocused\.com [NC]
4     RewriteRule \.(jpe?g|gif|bmp|png)$ http://google.com/res/images/blockimg.jpg [NC,R,L]

line 3 is your domain,
line 4 is your image url for display if sb used your images's url directly at his/her website.

As the example code shown above,
line 3 was set as "http://www.naturefocused.com", if sb used <img src="http://www.naturefocused.com/images/test.png"> at their website, it displays image "http://google.com/res/images/blockimg.jpg".

Remarks:
The error message image better if isn't using the domain you specific in line 3

Reference
http://www.naturefocused.com/articles/image-protection.html

No comments :

Post a Comment