Home » Blogger Tutorials, Blogging Made Easy, Blogging World, How to, Programming, Tutorials, Web World, WordPress

Using .htaccess to Prevent Images Hotlinking & Saving your Web Hosting Bandwidth

25 October 2009 Comments


Stumble Upon
Share

Did you ever noticed that your images are being hotlinked on someone else’s server and consuming your server bandwidth? This is actually is direct linking to a web site’s files (images, video, etc.).without your permission.

It is bad, as it not only stealing our images, it also take advantage of our bandwidths. Since web hosts charge based on the amount of data transferred, bandwidth is an issue.

Hotlinking should be stopped because others undesirable consequences like switcheroo can often occur.

Using control over.htaccess is one of the most efficient way to prevent image hotlinking. Go through the following steps:

Creating & Placing .htaccess in Root (main) directory

Simply open a notepad & save it as .htaccess without any extension behind. If already have the .htaccess uploaded to your server, simply edit it like in step 2.

Editing .htaccess File

Paste the following code in the .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursite2.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://yoursite.com/other_image.jpe[NC,R,L]

Note: In Last line of the above code the image other_image.jpg is not hotlink protected or your server can go into an endless loop.

In the above code yoursite2.com can used be stop hotlinking from specific outside domains only, such as myspace.com, blogger.com and livejournal.com

If you want to display 403 Forbidden error on hotlinking simply paste the following code instead of the code shown above.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursite2.com [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

Remember, Hotlinked images can only be replaced by other images, not with an HTML page.

Using .htaccess to prevent hotlinking helps you block some legitimate traffic using these techniques.

What do you think about other ways to prevent images hotlinking on your blogs? Do you like this technique? Share with us your views.

Related Posts with Thumbnails

Related Posts

Enjoyed this post? Don't miss out on what's to
come. Sign up for free via RSS or email.
Get updates by Email
 

Search


blog comments powered by Disqus