Lunarpages Web Hosting Forum

Learn More About Lunarpages Hosting => Web Hosting Tutorials, FAQs and Resources => Topic started by: Hush on November 22, 2003, 08:47:15 PM

Title: How To: Correct the issue with hotlink protection
Post by: Hush on November 22, 2003, 08:47:15 PM
The Issue

Hotlink protection is undeniably a good thing.  However, when using the tool in CPanel, it will not support browsing to the domain without the trailing / mark.  That means that

Quote from: Supported Addresses

http://www.yourdomain.com/
and
http://www.yourdomain.com/index.htm


Will show your images as expected, however,

Quote from: Un-supported Addresses

http://www.yourdomain.com


will not.  At this point, I should point out that CPanel is not a Lunar Pages product, so whilst we make recommendations for updates, we are not directly able to control these updates.

To make the hotlink protection work correctly, you will need to do a small amount of editing to your .htaccess file.  No this How To: is concentrating on protecting your whole site, I will deal with protecting parts of your site in another How To: and so you will be using the .htaccess found directly inside your public_html folder today.

To make this tutorial as easy as possible we will be using the Hotlink Protection tool inside CPanel.  So start by logining into your account, and clicking on the Hotlink protection icon.  The first thing you should notice is the very large white box on the screen.  This is where you type in the URLs that you want to allow to 'Hotlink' to your site.

Simply type in the urls that you want to allow to hotlink as you would type them into a browser, for example our URLs would be typed:

Quote from: Lunar Forums Example URL

http://www.lunarforums.com


Be sure only to type in the format above, do not worry about typing addresses with and without the www. prefix, or with a page afterwards, such as index.htm, as we will take care of this soon.

Click on the 'Activate' button.  This will automatically generate the basic hotlink protection scripting for your .htaccess file, and of course put it in place.

Next step, is to go back to the CPanel (click the 'home' icon on the CPanel banner). Click on File Manager, then click on the folder icon next to public_html to enter the folder, followed by clicking on the word .htaccess.  On the right hand side of the screen, a menu will appear, click on 'edit file'.

What you should see is a screen with some lines of code as follows (I have used the lunarpages and lunarforums from above, your code will have your domain in it)

Quote from: Code Entered Into .htaccess By Hotlink Protection

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.luarforums.com/.*$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]


Now, here's the good bit.  I want you to change the text to include the parts below in red, so it looks like this example.

Quote from: Changes To .htaccess Codes

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?lunarforum.com(/)?.*$     [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]


Click on the save button at the bottom of this page.  That's it, your site is now hotlink protected, and people will be able to view the site from just typing in your domain name, even without the trailing / mark.
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on November 23, 2003, 03:46:03 PM
Excellent, Hush!  Thanks!

This REALLY was a useful tip!  I had already read another thread that you shared this info, so I had done it a few days ago, but just wanted to let you know how GREAT this tip was!
Title: How To: Correct the issue with hotlink protection
Post by: Hush on November 24, 2003, 06:33:47 AM
Oh gosche...  :oops:  Thanks.
Title: How To: Correct the issue with hotlink protection
Post by: jsinger on December 09, 2003, 01:43:07 PM
I tried the hotlink protection in my .htaccess file but it doesn't seem to be working.

I have this in my .htaccess file (located in my public_html directory):
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?jeffsingerphotography.com(/)?.*$     [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]

I then created the following page to test it:
http://homepage.mac.com/jhsinger/testhotlink.html

I'm still seeing the image being linked.

Jeff
Title: How To: Correct the issue with hotlink protection
Post by: Hush on December 09, 2003, 01:47:34 PM
I have just visited the site you have given in your message, and the image is not showing.

I would say that this is probably cached.  Try emptying your temporary internet files/cache and reloading the page.
Title: How To: Correct the issue with hotlink protection
Post by: jsinger on December 09, 2003, 01:50:29 PM
Hmmm, I cleard my cache and it was still showing up... but I did it again after a reboot now its not showing up... DOH!

Jeff
Title: How To: Correct the issue with hotlink protection
Post by: Hush on December 09, 2003, 01:54:21 PM
The power of the Internet, and ghosting files  :?

Glad it's working for you though...  Hotlink protection can be a major factor in reducing a web site's bandwidth use.
Title: How To: Correct the issue with hotlink protection
Post by: jsinger on December 09, 2003, 02:07:34 PM
Yes, its of particular interest to me as a photographer.

On a related note, how does this (if at all) effect search engine spiders and how they crawl my site?
Title: How To: Correct the issue with hotlink protection
Post by: StephanieŽ on December 09, 2003, 02:31:00 PM
It won't affect your search engine ratings.

Most bots look for Meta tags/descriptions/keywords and links, images are not an issue.
Title: How To: Correct the issue with hotlink protection
Post by: mscnts on December 28, 2003, 05:00:10 PM
Hello.. would you be so kind to explain exactly what 'hotlink protection' is all about?
These 'how to:' posts are great and detailed, but unless you know what you want to do and why, they don't help us green beginners... lol   It would be perfect if you could start a 'how to' with a 'what this is/does/creates' paragraph.  Much appreciated!
Title: How To: Correct the issue with hotlink protection
Post by: Hush on December 28, 2003, 05:30:48 PM
Sorry,  that is an absolutely excellent point.

Hotlink Protection 101:

When you place files on your server (for instance images and video files), they can be viewed by anyone who visits your web site.  This takes up an amount of bandwidth (the size of the file).  However it is possible to link from one site to another and display files.

For instance, if you look through the graphics forum here at Lunar Forums you will see many images on display.  These images are hosted at the web site of the person who posted them.  A link to the image is added to the post in a similar way as if this forum were the person's own site.  This then takes the image from the user's site to display here.  This means that the user will have their bandwidth used for displaying the image.

This is known as hotlinking.  It can be put to great use.  However it can also be abused.  Imaging if you have a video file that is 20 MB in size, and your site gets a hundred people a day view it.  No real problem, your monthly bandwidth usage for this file will be approximately 60 GB (roughly calculated for simplicity).  However, someone sees this video and want's it on their site.  If they downloaded it, and then uploaded directly to their server to link to, it wouldn't impact your bandwidth.  However, say they are expecting 500 people to view it every day.  They may just link to the file on your server, so as not to use up their bandwidth.  Now your monthly bandwidth for this file may go up to 360 GB!

Hotlink protection stops files from being linked to, or viewed directly.  However, you are able to specify which domains are able to hotlink to your media in order that you can, for example, post images on forums.

Thanks for asking, it is all too easy to write the answer, when many people who view it will not be aware of the question.  :thumb:
Title: How To: Correct the issue with hotlink protection
Post by: mscnts on December 28, 2003, 05:48:33 PM
Aaaahhhhh.... *she says, nodding in complete understanding of the explanation.*   That makes perfect sense to me now!

Thanks for the quick reply!
Title: How To: Correct the issue with hotlink protection
Post by: Hush on December 28, 2003, 08:12:23 PM
:D  All part of the service  :thumb:
Title: How To: Correct the issue with hotlink protection
Post by: EJ on January 13, 2004, 09:42:10 AM
Hey Hush???

heres what my says/looks like

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.graphics.steelsheen.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.graphics.steelsheen.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.steelsheen.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.steelsheen.com$      [NC]



Why are there "clones"? can I delete those? and which ones exactly would I delete?

edit: OK here's what it looks like now, I havent deleted those clones, Don't know if I should

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?graphics.steelsheen.com(/)?.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.graphics.steelsheen.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?steelsheen.com(/)?.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.steelsheen.com$      [NC]

Is this correct?
Title: How To: Correct the issue with hotlink protection
Post by: EJ on January 22, 2004, 05:48:51 PM
OK cpanel hot link sucks, sometimes it works sometimes it doesnt, my avatar was working now its not, yet oddly my pictures are still showing on other websites. I did everythng above. Everytime I update it (like adding a redirect url which doesnt work anyway!) I get 50 million clones...I give up :(
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on January 22, 2004, 06:02:12 PM
I found that out, too, EJ.  So now, I don't use the Hotlinks Protection via cPanel to update, I go straight into the .htaccess file and add things there.
Title: How To: Correct the issue with hotlink protection
Post by: Hush on January 22, 2004, 06:06:22 PM
Hello,

Sorry took a while to come back to this.  There are glitches every now and again, and if you are comforable just starting straight in .htaccess, this will always be better.  The lines of code can just be entered.

There is also a really handy tool available for free use at:HTML Basix (http://www.htmlbasix.com/disablehotlinking.shtml) please excuse the popup ads  :thumb:
Title: How To: Correct the issue with hotlink protection
Post by: EJ on January 23, 2004, 11:03:07 AM
Quote from: Hush
Hello,

Sorry took a while to come back to this.  There are glitches every now and again, and if you are comforable just starting straight in .htaccess, this will always be better.  The lines of code can just be entered.

There is also a really handy tool available for free use at:HTML Basix (http://www.htmlbasix.com/disablehotlinking.shtml) please excuse the popup ads  :thumb:


No problem Hush,

Do I need to disable hotlink protection, first? And I'll check out that link, Thanks


edit:everything seems to be working, so I'll leave it be
Title: How To: Correct the issue with hotlink protection
Post by: datahomi on February 01, 2004, 05:45:10 PM
tks for the tip!

im tryin to do it now!
Title: How To: Correct the issue with hotlink protection
Post by: dfaonxa on April 08, 2004, 07:01:44 AM
Okay, I'm dredging up an old subject here, but... I've been having this precise problem (that when I think about it occurred when I altered my .htaccess file to deny hotlinking), but when I made the changes suggested (I simply copied/pasted the text and changed it to my domain name), my page returns a 500 error.  Any suggestions?
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on April 08, 2004, 10:47:40 AM
Did you edit the htaccess file in cPanel, or in Notepad the uploaded via FTP client?  If you did the latter, did you upload in ASCII mode?  If you didn't, then it probably uploaded in binary and that may be the problem.

Try again.
Title: How To: Correct the issue with hotlink protection
Post by: dfaonxa on April 08, 2004, 01:09:20 PM
I did it over FTP, so I tried uploading in ASCII and it still gives me the same problem.  I haven't been able to get into cPanel lately (404 errors) so I haven't been able to try that yet.
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on April 08, 2004, 01:17:21 PM
Post what your htaccess file looks like.
Title: How To: Correct the issue with hotlink protection
Post by: dfaonxa on April 08, 2004, 05:01:47 PM
AddHandler server-parsed .htm

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http:// ( www \ . )? passionbreedsfollowers.com ( / )? .*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ - [F,NC]


(the first line to enable hidden SSI)
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on April 08, 2004, 05:23:38 PM
You have spaces where there shouldn't be.  This line should look like this:

Code: [Select]

RewriteCond %{HTTP_REFERER} !^http://(www\.)?passionbreedsfollowers.com(/)?.*$ [NC]


Remove the space in front of "passion" and after ".com" (you can just copy the above line and paste over the original line in your .htaccess), then it should work.

I don't know anything about the SSI line, so if the above still doesn't work, then it could be that first SSI line you have that's causing the problem.

Again, I don't know much about the SSI line, but if it's an Apache Handler, aren't you supposed to add it in the Apache Handler section of cPanel?

Someone may be able to verify this, as I don't know much about Apache Handlers.
Title: How To: Correct the issue with hotlink protection
Post by: dfaonxa on April 08, 2004, 05:37:58 PM
AHA, it finally works!  Thanks so much for your help!   :yey:
Title: How To: Correct the issue with hotlink protection
Post by: Amy on April 17, 2004, 02:16:52 PM
Just tried this, and the original post inserts a space with the colour tag

Quote from: leighsww
You have spaces inserted where there shouldn't be.  It should look like:

Code: [Select]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain1.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain2.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sub.domain1.com(/)?.*$ [NC]
RewriteRule .*\.(gif|bmp|jpg|png|zip|rar|exe)$ - [F,NC]


You probably copied and pasted Hush's code, but he had put in the color tags to make some parts RED which inserts a space.


Thanks for the help
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on April 17, 2004, 02:44:34 PM
Good that you posted that in this thread, Visitor, because this will be a problem for a lot of others (as it was for you and dfaonxa), when they copy and paste the code with the RED tags in it.

Hopefully, people will read through this entire thread, so that they remove the spaces.

Hush - maybe you should revise your original post to have a "Copy and paste this version" (for example) so that they don't copy the one with the RED tags. The one with the RED tags is still good to show where the changes occur, but the "copy & paste" version will be what they can actually use for the htaccess file.
Title: How To: Correct the issue with hotlink protection
Post by: Amy on April 27, 2004, 01:14:04 PM
In the end I found by just adding...
RewriteCond %{HTTP_REFERER} !^$

fixed the problem anyway :)
Title: Still valid?
Post by: satirista on May 23, 2004, 06:10:23 PM
Hi!

Is this still an issue and a valid fix?

If so, I have a question...

In my .htaccess file, my site name shows up in various permutations, including:

!^http://elizabethhanes.com/.*$
!^http://elizabethhanes.com$
!^http://www.elizabethhanes.com$
!^http://www.elizabethhanes.com/.*$

Do I need to modify the ones without the "www"? If so, how?

Do I need to modify the ones without the slash at the end? If so, how?

Thank you very much for this useful feature and for your wonderful explanation of how to make it work properly!

Elizabeth
Title: How To: Correct the issue with hotlink protection
Post by: leighsww on May 23, 2004, 06:36:14 PM
Elizabeth -

By looking at your code, it looks like LP might have changed the "hotlinks protection" script, so that the trailing frontslash issue is resolved now without having to revise the "htaccess" file as originally explained (I am not 100% certain about this, though).

But just for your info, this:

Code: [Select]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?elizabethhanes.com(/)?.*$ [NC]

would take the place of all those four lines.

However, since your domain is working with and without the trailing frontslash as it is (I just checked), best you just leave your htaccess file alone.
Title: How To: Correct the issue with hotlink protection
Post by: satirista on May 23, 2004, 07:12:42 PM
Thanks, leighsww. I appreciate the update. I don't have qualms about doing things like editing the htaccess, but on the other hand, I don't like to go messing with it if I don't have to!

Elizabeth
Title: How To: Correct the issue with hotlink protection
Post by: vcheewei on June 26, 2004, 07:08:32 PM
Hello everyone, i had a problem over here. I own a links site. It grows quite fast and became popular. I have a logo which i allow alot of sites to direct linking to it. It was a .jpg file. So i do not wish to block that.
My layout's images and other stuff are in gif.


Recently, i found out that people is using IFRAME tag to link to my main page.

Which is a .php file. Is that a good idea to block .php files?

Code: [Select]
RewriteRule .*\.(gif|php)$ - [F,NC]

Will search engine stop listing me?
Also, i would wanna know is that anyway in php coding that i can block the referal url coming from that page and redirect him to other page?

Please help, those people are bandwidth suckers. My bandwidth always exceeds.
Title: How To: Correct the issue with hotlink protection
Post by: MPG on June 26, 2004, 09:44:43 PM
I have been having some of the same problems mentioned here.  The problem is using cPanel along with editing the .htaccess file.  I posted in another forum all my .htacces code with the problem but never got a response.  I have a bit of a different problem.  

I need to protect my site from people grabbing images and huge files, while still being able to call images from code pointing to them from other areas.  I also have the problem of having my site located in a directory "/main" because I use phpnuke.  This all sounds simple but for some reason it hasnt been. . .

I plan on posting the code and problem in total detail here, but I have to sort it out into a legible format for this forum because I think no one answered my last post because it was too confusing.  Also wanted to see if anyone was up for the challenge.

more to come soon.
Title: How To: Correct the issue with hotlink protection
Post by: mongo106 on February 11, 2005, 03:22:44 AM
Quote from: jsinger
Hmmm, I cleard my cache and it was still showing up... but I did it again after a reboot now its not showing up... DOH!

Jeff


You're not by chance a Jeff Singer that lived in De Luz California are you?
Title: How To: Correct the issue with hotlink protection
Post by: vizcares on April 01, 2005, 02:19:12 PM
Quote from: Hush
Hotlink protection stops files from being linked to, or viewed directly.  However, you are able to specify which domains are able to hotlink to your media in order that you can, for example, post images on forums.


Is it possible to make it the other way around, that means, allow everybody to hotlink, except one place?

the case is that someone is taking a .htm page and making it look like theirs, so I would just stop people from that one site to get to my file

Thanks in advance
Title: How To: Correct the issue with hotlink protection
Post by: Razzelle on May 31, 2005, 07:15:25 AM
Okay, I have a question.  I want to add a message board to be able to link to my site....how do I add it.

I tried in the cpanel hotlink part, doesnt work.  Why does this hotlink have to be such a pain?


What line do I add in my .htaccess edit from the file manager to get this to work?

and do I just add the name of the forum as such.


Code: [Select]
www.forum/forumname/index.php?

to allow the forum to hotlink?