Forum Moderators: phranque
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]
Thanks in advance!
[edited by: jdMorgan at 1:16 am (utc) on Feb. 9, 2006]
[edit reason] De-linked, formatting. [/edit]
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