One of the most annoying problem for every blog or website owner is how to protect your hosted images and files on your website, If you usually have lots of images on your site you may noticed that some people start linking (Hotlinking) to these images and this of course will increase your bandwidth usage.
So it’s very important that you protect files and images on your site to save your bandwidth, the way to do this is by using the htaccess on your host to protect your files and images.
How to protect your images?
Open up your htaccess and modify it with the following code, You need to change yoursite.com with your domain name.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yoursite.com(/)?.*$ [NC]
RewriteRule .(gif|GIF|jpg|JPG)$ /hotlinking/banned.gif [L,NC]
in this line /hotlinking/banned.gif you can define image with text on it for example (banned image), this image will be displayed instead of your hosted images if someone tried to link to your images outside your site.
If you have other images extensions you can add to (gif|GIF|jpg|JPG).
How to protect your images?
The following code will completely forbid any one try to download files outside your website, and will redirect it to your website.
just change yoursite.com with your domain name, and change redirecturl to the url that you want to shoe when someone try to download yourfiles. Also add any other files extension you want to protect to (rar|RAR|ZIP|zip)
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www.)?yoursite.com/.*$ [NC]
RewriteRule .(rar|RAR|ZIP|zip)$ http://www.redirecturl.com [R,L]
Now what if you wanted to specify a cretin websites to allow them to show your images and download your files?
You can add this code if you wanted to allow some website (friendlysite) to show you images or download your files, and change friendlysite to the sites that you want to allow.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.friendlysite1.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://friendlysite1.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.friendlysite2.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://friendlysite2.com.*$ [NC]









No Comment Received
Leave A Reply