Return to iWEBTOOL

Go Back   iWEBTOOL Talk > The Web and your Website > Web Development
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
Welcome to iWEBTOOL Talk, where you talk about webmaster-related stuff.
 
Discuss topics which interest you.
With over thousands of threads (topics), we're sure you'll find something that'll interest you.
Ask for help whenever you need it.
We have thousands of members who are available to help you if you need it.
It's absolutely FREE!

 1  Register           2  Browse the board           3  Discuss whatever may interest you!
 


Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 07-26-2006, 01:09 PM   #1
NeutralizeR
Junior Member
 
NeutralizeR's Avatar
 
Join Date: Jul 2006
Location: Ankara/TR
Posts: 26
NeutralizeR will become famous soon enough
Send a message via MSN to NeutralizeR
Post Hotlink Protection Tutorial (Apache Server - .htaccess files)

What is hotlinking and bandwidth theft?

Bandwidth theft or "hotlinking" is direct linking to a web site's files (images, video, etc.). An example would be using an <img> tag to display a JPEG image you found on someone else's web page so it will appear on your own site, eBay auction listing, weblog, forum message post, etc.

Bandwidth refers to the amount of data transferred from a web site to a user's computer. When you view a web page, you are using that site's bandwidth to display the files. Since web hosts charge based on the amount of data transferred, bandwidth is an issue. If a site is over its monthly bandwidth, it's billed for the extra data or taken offline.

A simple analogy for bandwidth theft: Imagine a random stranger plugging into your electrical outlets, using your electricity without your consent, and you paying for it.

How Do I know I am hotlinking?

This is how you might display an image graphic file in the HTML on your own web page:
HTML Code:
<img src="image.jpg" height="350" width="200">

This tag tells the site to request the file image.jpg on the same server as the rest of the files on the site. If you were to hotlink an image from an outside server, the HTML might look like this:
HTML Code:
<img src="http://notmysite.com/image.jpg" height="350" width="200">

This tag tells the site to request the image.jpg from a different server other than your own. Every time the page is loaded, the outside server has to use its bandwidth to display the image. To avoid this problem, don't link to files on servers that don't belong to you. To share images and files on your own web page, upload them to your own server's directory or to a free image hosting service that allows direct linking.

Why should I stop hotlinking?

Hotlinking can have a lot of undesirable consequences. One is the so-called "switcheroo". If you've linked to an image on someone's server, what's to prevent them from changing the image you linked to? This can have humorous results. Since most sites, forums, etc. have strict policies about offensive images, it wouldn't take much for an aggravated webmaster you've been stealing bandwidth from to shut you down completely with an unwanted "switcheroo".

Displaying an image or file that doesn't belong to could be a violation of copyright, making you open to litigation. The owner of the file could utilize DMCA law to have your site shut down and your information given for use in legal proceedings.

How can I test to see if my image can be hotlinked?

Use our URL hotlink checker below to check the hotlinking protection (such as an htaccess file) on your web site. Enter the complete URL below (ex: http://mysite.com/image.jpg) to see if your image can be loaded and hotlinked by an outside server.

Click to go to the Resource & Test Page

******************************************
******************************************
******************************************
Following text may not be an ultra professional experience but i've been using these techniques for 2 years and they are working great for me.

I've been running two dedicated servers and i've full control over them (my .htaccess file lines included in my httpd.conf file). If your hosting is shared and got some restrictions to use .htaccess files on your account, you should contact your hosting company first to enable them.
Notice: .htaccess files can only be used by Apache web servers and they will not work on a windows system.

Hotlink Protection Enabled .htaccess File Tutorial

-Create a new TXT file named *'sample.htaccess' and open it with your text editor (NotePad). *Windows users won't be able to create it as '.htaccess' so you have to rename 'sample.htaccess' to '.htaccess' after it's been uploaded to your server.

-Copy and paste the following lines to 'sample.htaccess' file:
Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|swf)$ http://www.yourdomain.com/forum/ [R,NC]
-Change http://www.yourdomain.com with your domain name.
-Upload 'sample.htaccess' file to your web server's root and rename it to '.htaccess'.

Read the following text to figure out how to customize your own .htaccess file.

RewriteCond %{HTTP_REFERER} !^$ = Allow direct requests (ie. entering the url to an image in your browser). People can't publish your image files at their own web pages but they still can view them by entering their url in the browser window. These images can also be viewed (shared) by clicking on their urls in Instant Messenger windows.

[NC] = "No Case", meaning match the url regardless of being in upper or lower case letters.

[R] = Redirect

*(jpg|jpeg|gif|png|bmp|swf) = Files to block

I used to redirect blocked files to a custom .jpe image file. If you prefer this option, you should use the following .htaccess file:
Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|swf)$ http://www.yourdomain.com/nohotlinking.jpe [R,NC]

Upload a tiny jpg file with a text on it like "Hotlinking is not allowed!" and change it's extension to .jpe. This JPEG image is using the extension jpe instead of jpg to prevent blocking your own replacement image.

My .htaccess file:
Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.msxlabs.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.msxlabs.org$ [NC]
RewriteRule .*\.(mp3|mpeg|mpg|ram|rm|wma|wav|asx|wmv|avi|mov|z ip|rar|exe)$ http://www.msxlabs.org/forum/ [R,NC]

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.msxlabs.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.msxlabs.org$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|swf)$ http://www.msxlabs.org/forum/ [R,NC]

This .htaccess file redirects people to my forum homepage who are trying to access the file types which are listed in the blocked files list.

First piece of lines got RewriteCond %{HTTP_REFERER} !^$ line as i don't want people to be able to access those kind of files directly. (The protection for the image files doesn't have that line)

If you don't want a redirection for (mp3|mpeg|mpg|ram|rm|wma|wav|asx|wmv|avi|mov|zip|r ar|exe), you can use replace that line with the following display your Error Code 404 page:

Quote:
RewriteRule .*\.(mp3|mpeg|mpg|ram|rm|wma|wav|asx|wmv|avi|mov|z ip|rar|exe)$ [F,NC]

Example: 404 - MsXLabs

.htaccess files effect the folder it's in and all of the subfolders.

If you want to exclude a subfolder from the hotlink protection, create another .htaccess file with the lines below and upload it to that directory:
Quote:
RewriteEngine on
RewriteRule ^.*$ -


IMPORTANT NOTE: PLEASE DELETE ANY EXTRA SPACES ADDED BY VBULLETIN. (jpg|jpeg|gif|png|bmp|swf) THERE SHOULD'T BE ANY SPACES BETWEEN THE EXTENSION TYPES.
Feel free to reply this thread if i made some mistakes :rolleyes:

This tutorial is written by NeutralizeR @ MsXLabs Organization
Original Thread
NeutralizeR is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
SEO Checklist
Get yourself better ranking with
our "Do-it-Yourself" SEO Checklist.
Click Here
Old 07-26-2006, 01:25 PM   #2
Katey
Senior Member
 
Katey's Avatar
 
Join Date: Apr 2006
Location: Hull, United Kingdom.
Posts: 317
Katey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud of
Default Re: Hotlink Protection Tutorial (Apache Server - .htaccess files)

Hi there,

In cPanel I'm sure there is a feature which makes this process a lot easier. I have had a break from being a webmaster so I am forgetting quite a lot so correct me of I'm wrong. Thanks for the tutorial anyway I'm sure a lot of people will learn a lot from this.


Regards,
Kieran Taylor.
Katey is offline  
Old 07-26-2006, 01:26 PM   #3
jumpenjuhosaphat
 Contributor 
 
jumpenjuhosaphat's Avatar
 
Join Date: Jun 2006
Location: Denver
Posts: 4,459
jumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud ofjumpenjuhosaphat has much to be proud of
Default Re: Hotlink Protection Tutorial (Apache Server - .htaccess files)

Thanks for the good information. Would it be possible to completely pull a hotlinkers visitor into my own site using .htaccess? I mean, instead of sending them the .jpe file, could you send them a webpage with your own links on it?
__________________
Storage Sheds
Lost Forum
jumpenjuhosaphat is offline  
Old 07-26-2006, 01:52 PM   #4
NeutralizeR
Junior Member
 
NeutralizeR's Avatar
 
Join Date: Jul 2006
Location: Ankara/TR
Posts: 26
NeutralizeR will become famous soon enough
Send a message via MSN to NeutralizeR
Smile Re: Hotlink Protection Tutorial (Apache Server - .htaccess files)

Quote:
Originally Posted by KieranTaylor0403
Hi there,

In cPanel I'm sure there is a feature which makes this process a lot easier. I have had a break from being a webmaster so I am forgetting quite a lot so correct me of I'm wrong. Thanks for the tutorial anyway I'm sure a lot of people will learn a lot from this.


Regards,
Kieran Taylor.

Yes, i used cPanel's hotlink protection feature,too. But cPanel doesn't give you this much customization and this way it's a more flexible solution.


Quote:
Originally Posted by jumpenjuhosaphat
Thanks for the good information. Would it be possible to completely pull a hotlinkers visitor into my own site using .htaccess? I mean, instead of sending them the .jpe file, could you send them a webpage with your own links on it?

Of course, first sample redirects to your forum home.

Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|swf)$ http://www.yourdomain.com/forum/ [R,NC]

You can replace it with any url in your domain.

This image is located in a hotlink protected directory:
------- > It must be broken here. (Hotlink protected with forum home redirection)

This line allows it to be viewed by an empty referrer:
Quote:
RewriteCond %{HTTP_REFERER} !^$
Copy the url below, open a new browser window and paste in to address bar:
http://www.msxlabs.org/images/acting...sxlabs.com.gif

Once it's cached by your browser, you can view the image above in this post, too.

I used to redirect hotlink protected image files to a small gif file which was located in a non-hotlink protected directory:


Non-image files are always being redirected to my forum homepage.

Last edited 07-26-2006 at 02:13 PM.
NeutralizeR is offline  
Old 07-26-2006, 11:10 PM   #5
Katey
Senior Member
 
Katey's Avatar
 
Join Date: Apr 2006
Location: Hull, United Kingdom.
Posts: 317
Katey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud of
Default Re: Hotlink Protection Tutorial (Apache Server - .htaccess files)

Hi there,

If you ever have any other tutorials please post them, as I always want more things to read and learn.


Regards,
Kieran Taylor.
Katey is offline  
Old 07-27-2006, 08:44 AM   #6
NeutralizeR
Junior Member
 
NeutralizeR's Avatar
 
Join Date: Jul 2006
Location: Ankara/TR
Posts: 26
NeutralizeR will become famous soon enough
Send a message via MSN to NeutralizeR
Default Re: Hotlink Protection Tutorial (Apache Server - .htaccess files)

Quote:
Originally Posted by KieranTaylor0403
Hi there,

If you ever have any other tutorials please post them, as I always want more things to read and learn.


Regards,
Kieran Taylor.
My main web site has six main sections and only two of them are currently online, other sections are under construction... I'll translate my Turkish tutorials to English and write more when i have enough time. Thanks
NeutralizeR is offline  
Old 07-27-2006, 09:33 AM   #7
Katey
Senior Member
 
Katey's Avatar
 
Join Date: Apr 2006
Location: Hull, United Kingdom.
Posts: 317
Katey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud ofKatey has much to be proud of
Default Re: Hotlink Protection Tutorial (Apache Server - .htaccess files)

Hi there,

Cool, thank you.


Regards,
Kieran Taylor.
Katey is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
Webmaster Tools Webmaster Tools Click Here
Closed Thread

(Threads which have no activity for more than 30 days are automatically closed.)



Quick Reply
Message:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help optimizing Flash/GIF files for fast loading satlas Web Development 7 12-08-2006 11:17 PM
Adware Spyware Removal & Computer Protection Guide ev8321 Advertise your website 4 11-14-2006 11:42 AM
Server UnKnown Help and Support 4 08-31-2006 04:36 PM
Did the server crash? Albert Tai Help and Support 2 06-27-2006 05:57 PM


All times are GMT. The time now is 05:42 AM.


Powered by vBulletin v3.6.7 © 2008, Jelsoft Enterprises Ltd. SEO by vBSEO © 2006, Crawlability, Inc.