Correct way to use Hotlink protection

YukFoo

Well-Known Member
Sep 1, 2002
134
0
166
What's the correct way to use hotlink protection. When we try and only protect downloadable files from being linked to (our own music files), it doesn't work. Sometimes our images don't even show up. These file extensions we are trying to protect are .mp3 and .m3u
 

AlaskanWolf

Well-Known Member
Aug 11, 2001
535
0
316
Fremont CA
when you go to your url, make sure you have / at the end

domain.com is not the same as domain.com/ when it comes to hotlink protection
 

SprintSlash

Well-Known Member
Jan 18, 2003
162
0
166
Is there a way to make sure domain.com gets redirected to domain.com/ immediately?
 

Website Rob

Well-Known Member
Mar 23, 2002
1,501
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Add the following to an .htaccess file and place it in Document Root for the account in question.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.trusted.com/.*$ [NC]
RewriteRule .*\.(gif|jpg|)$ - [F,L]

The 'RewriteRule' is where you include the same file extension of the files to be protected.

Using what was previously mentioned:

RewriteRule .*\.(gif|jpg|mp3|m3u)$ - [F,L]

The above code is case-sensitive and works with most Servers -- but not all -- depending upon the OS used and setup.
 

HankScorpio

Registered
Feb 26, 2003
4
0
151
This is the cPanel forum.
The problem as stated is that cPanel hotlink protection does not work.
cPanel does generate an .htaccess file for you via the GUI but the way it is formatted means that on some systems, it does not work. That is why the question has been asked here.
 

SoftmegUK

Well-Known Member
Feb 13, 2002
368
0
316
UK
Originally posted by moronhead
OK, where do you want me to send you the 50 bucks? :D
he says he would prefer if you sent it to my paypal account first :p
 

Website Rob

Well-Known Member
Mar 23, 2002
1,501
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Originally posted by HankScorpio
This is the cPanel forum.
The problem as stated is that cPanel hotlink protection does not work.
cPanel does generate an .htaccess file for you via the GUI but the way it is formatted means that on some systems, it does not work. That is why the question has been asked here.
Yo, stick a sock in it or answer the question asked -- either one will do nicely, thank you. :D
 

HankScorpio

Registered
Feb 26, 2003
4
0
151
The .htaccess file that cPanel generates has extra whitespace at the end of some of the lines, on the four cPanel domains I have or had, when the lines are trimmed back to the last character, it worked for me.
I can't explain why, I can only say that it does.

Robs example would work fine if you created your own but like many people, I initially didn't know about the .htacess file and I wanted it to work from the GUI. I spent a lot of time looking into the problem, cutting and pasting and generating new files, testing etc.
The solution above was what I found worked.

Apologies if the tone in the previous posts was offensive, the inital post did have a ;) in it and Rob's first post offered a solution but not a cPanel solution which is what people here are looking for.
 

Website Rob

Well-Known Member
Mar 23, 2002
1,501
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Apologies accepted (although not required) and my compliments on a much better answer! ;)

The only difference between your suggestion and and mine is that I went by the question: "Correct way to use Hotlink protection" whilst you appended: "when using the Cpanel Hot Link feature."

As the original question was months old and the poster may not know there has been updates to it, we may never know if the Hot Link prevention feature of Cpanel was the problem. As the most recent post, which is what I responded to, simply stated: "please tell me", that's exactly what I did -- and it will work regardless of using/not using Cpanel.

Your answer, Hank, allows people to use an 'either / or' solution and, between our two answers, they now have the best of both worlds. :D
 

Crazy Pete

Well-Known Member
May 16, 2003
55
0
156
Originally posted by Website Rob
The 'RewriteRule' is where you include the same file extension of the files to be protected.

Using what was previously mentioned:

RewriteRule .*\.(gif|jpg|mp3|m3u)$ - [F,L]

The above code is case-sensitive and works with most Servers -- but not all -- depending upon the OS used and setup.
What does the L do in this command? On my server it breaks every single image, so they always just show up as the broken image icon. It I just have the F it works, however.

cPanel.net Support Ticket Number:
 

NightHawk

Member
Apr 17, 2003
22
0
151
well..if you want a way to do it outside of cpanel...but that will work....and you don't want to modify the .htaccess listed above...then you could always just do it the easy way....goto this url: http://www.htmlbasix.com/disablehotlinking.shtml ..fill in the blanks..and use the .htaccess it generates....

hope that helps :cool:

cPanel.net Support Ticket Number:
 

Crazy Pete

Well-Known Member
May 16, 2003
55
0
156
Thanks very much for that link, NightHawk! That's pretty cool. Turns out it was working after all, but that might help in the future anyhow.

cPanel.net Support Ticket Number:
 

Website Rob

Well-Known Member
Mar 23, 2002
1,501
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Originally posted by Crazy Pete
What does the L do in this command? On my server it breaks every single image, so they always just show up as the broken image icon. It I just have the F it works, however.

cPanel.net Support Ticket Number:
The 'L' stands for Last, as there can more than one Rewrite rule. Leaving it off, if you only have one rule such as in this case, is no biggee and does not change how the rest of the code works.

The 'F' in case you were wondering, stands for Fail. Some people like to use 'R' (for Redirect), but I don't follow that philosophy and just want to stop the bandwidth thieves -- period!

BTW, nice link you posted there,
NightHawk. Should help those that are having problems and not sure what to do.

cPanel.net Support Ticket Number:
 

infinityws

Well-Known Member
Feb 20, 2003
110
0
166
Everything on my end is working great, but the things I want to protect are realvideo clips. However to download them it goes through a counter script which, when hotlink protection is active, won't work.

cPanel.net Support Ticket Number:
 

NightHawk

Member
Apr 17, 2003
22
0
151
Originally posted by infinityws
Everything on my end is working great, but the things I want to protect are realvideo clips. However to download them it goes through a counter script which, when hotlink protection is active, won't work.

cPanel.net Support Ticket Number:
have you tried listing the counter script as a referrer in your hotlink .htaccess ??

cPanel.net Support Ticket Number:
 

outie

Member
Mar 22, 2003
15
0
151
Speaking of hotlink protection... one of my clients has a huge traffic site. His site is for image upload and some large forums link the images from his site.

He used hotlink protectioin to protect other people from linking images from his site (to save bandwidth) and directed them all to one single image file.

This created a huge server load on my server (70% on a p4 1.7). Is that normal or he didn't do it right? When he removed the redirect protection it was down to 1% load.

cPanel.net Support Ticket Number: