Forum Moderators: phranque

Message Too Old, No Replies

Deny hotlinking for all sites using .htaccess

One that works

         

silverbytes

8:30 pm on Feb 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Would you mind to help me deny hotlinking using .htaccess for all sites please?

someboyd posted this one but gives 500 internal server error so I'd prefer a fresh one, if tested, better!

RewriteEngine On 
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?myspace\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blogspot\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?livejournal\.com/ [NC]
RewriteRule .*\.(jpe?g¦gif¦bmp¦png)$ /images/nohotlink.jpe [L]

wilderness

8:43 pm on Feb 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you correct the forum errors for the broken pipe characters?

Replacing inline linked images with another image is generally not a sound decision.
A better practice is simply to deny.

I use the following:


RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?MyDomian\.(com¦net) [NC]
RewriteRule \.(jpg¦gif¦pdf¦ico)$ - [NC,F]

[edited by: jdMorgan at 12:58 am (utc) on Feb. 9, 2008]
[edit reason] Just a formatting fix [/edit]

silverbytes

12:40 am on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And the [NC,F] part is the deny? Does that make a 403?

g1smd

12:43 am on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I forget whether it is a 401 or a 403, but a HTTP Header Checker will show you in seconds.

The Live HTTP Headers extension for Mozilla Seamonkey and for Mozilla Firefox is very good.

jdMorgan

1:07 am on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes the [F] flag on RewriteRule generates a 403-Forbidden response, although some mod_rewrite coders have a slightly-different mnemonic to associate [F] with the intentionally-rude response to unwelcome visitors. ;)

Another vote here for the "Live HTTP Headers" add-on for Firefox/Mozilla browsers. If you write mod_rewrite code and don't already use it, then you're either wasting a lot of time, or you're not testing thoroughly enough. I plug it so hard that some accuse me of having an ulterior motive... Nope, I just use it two/three hours every day.

Also nice for checking out the competition's server setup, BTW... ;)

Jim

silverbytes

7:05 pm on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you all guys.