.htaccess Tutorial - Protect Images
To prevent people from linking to the images on your server that abusing your bandwidth, you can use the mod_rewrite module to filter the unauthorized requests.
1. Activate Protection
Add the following lines to your .htaccess file to stop people from hotlinking to your .gif and .jpg files.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your_domain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Replace your_domain.com with your domain name.
This starts by turning on the rewrite engine. Next, it checks the referer (where the request comes from).
If it did not come from your domain name and it is a request for a .gif or .jpg file, it will output an error message. Otherwise it will display the image as usual.
You can apply this with other file extension.