Forum Moderators: phranque

Message Too Old, No Replies

Please check .htaccess code [bandwidth protection]

Need to protect bandwith, yet allow Google Images; not sure code is correct

         

hfguide

12:53 am on Feb 9, 2006 (gmt 0)

10+ Year Member



Hello, everyone. I am going through a nightmare regarding hotlink protection, so am really toying with this whole .htaccess thing for the first time.

I have a site where I offer free images. I want to protect the images from being hotlinked; however, I'd like the images to be viewed from Google Images, even when the image's URL is called. I'd also like any hotlinked images to be replaced with a gif that posts a message [akin to "don't hotlink"].

I've been going through various .htaccess tutorial sites, but they all seem to code differently. I was able to pull together the following code but am unsure if this will do the trick. I also don't want to screw things up, because the last time I toyed with .htaccess I really messed things up. Does this look alright?

[Oh-- and if anyone's wondering, for the purpose of this post I've put *mydomain.com* in there on purpose]

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?google.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ http://www.mydomain.com/message.gif [R,L]

Also, how do I make sure that http://www.mydomain.com and http://mydomain.com are both listed as *friendly* referrers?

Thanks in advance!

[edited by: jdMorgan at 1:16 am (utc) on Feb. 9, 2006]
[edit reason] De-linked, formatting. [/edit]

jdMorgan

1:18 am on Feb 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is basically OK, but we really don't do code reviews. If you have any problems with it after testing, I'm sure it can be improved.

The (www\.)? sub-pattern means that your RewriteConds will match a hostname with or without a "www." prefix.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

hfguide

2:12 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



Thanks.