Forum Moderators: phranque

Message Too Old, No Replies

blocking all sites and redirecting

         

proxyHunter

5:16 am on Nov 22, 2003 (gmt 0)

10+ Year Member



I know how to block all domains except my own from hotlinking

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://mysite.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http:De//www.mysite.com.*$ [NC]
RewriteRule .*.(gif¦GIF¦jpg¦JPG)$ - [F]

but i also want to stop a few sites (some i don't know about) from doing this:

<img src="http://mysite.com/" width="1" height="1">

and adding to my bandwidth.

I do know how to stop domains with certain keywords:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} "cartoon" [OR]
RewriteCond %{HTTP_REFERER} "movies"
RewriteRule .* http://redirecthere.com [L]

but is there a way to stop all other sites and redirect them?

(this doesnt work)

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^http://mysite.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com.*$ [NC]
RewriteRule .* http://redirecthere.com [L]

[edited by: jdMorgan at 2:37 am (utc) on Nov. 24, 2003]
[edit reason] De-linked URLs [/edit]

jdMorgan

6:35 am on Nov 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



proxyHunter,

You have to use an external redirect if you want to send them off to another site. Fixing that, as well as combining your two RewriteConds into one, gives:


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com.*$ [NC]
RewriteRule .* http://redirecthere.com [R=301,L]

However, it may be more efficient to simply 403 them and be done with it:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com.*$ [NC]
RewriteRule .* - [F]

Or, if you have a custom 403 page:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com.*$ [NC]
RewriteRule!^my_custom_403_page\.html$ - [F]

Note with all of the code variants above, you will block anyone whose referer is blank. This will include anyone who enters your URL directly, uses a bookmark, or who is behind a corporate proxy or internet security program which blocks referrers. I believe that blocking blank referers is a bad idea, and will give most webmasters major 'customer support' headaches. Therefore, despite the fact that it opens a 'hole' in the hot-link blocking, I suggest you allow blank referers, like so:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com.*$ [NC]
RewriteRule!^my_custom_403_page\.html$ - [F]