Forum Moderators: phranque
<img src=www.mysite.co.uk/images/xxx.jpg>
I wish to display a specific image instead of the image they are attempting to access.
I've tried the following in .htaccess, to check for their domain as referer and act upon it, but it just displays the famous X (image missing):
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER} ^http://(www\.)?theirsite.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ [mydomain.co.uk...] [R,L]
I don't really know what I am doing with .htaccess, so thanks in advance for your help!
Stop direct linking to images [webmasterworld.com]
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.co.uk [NC]
RewriteRule \.(gif¦jpg)$ /images/7638.gif [NC,L]
I also recommend having an alternate image for each image type, gif, jpg, png, etc. and using this rewrite rule instead, along with the RewriteConds above:
RewriteRule \.(gif¦jpg)$ /images/7638.$1 [NC,L]
You can use wannabrowser (do a search) to test with any referrer you like.
Change the broken vertical pipe "¦" characters above to solid vertical pipe characters, and make sure these is a space preceding the "!" characters, as usual.
Jim
The reason for this is to redirect to a specific image, only if the referer is a specific site (for which I'll use www.specific-site.com in the example):
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER} ^http://www\.specific-site\.com/* [OR]
RewriteCond %{HTTP_REFERER} ^http://specific-site\.com/*
RewriteRule ^.*$ [redirect-image-url.co.uk...]
This I believe will only have effect if referers is enabled in browser/firewall AND the referer begins with [specific-site.com...] or [specific-site.com...]
Look ok?
I recommend having an alternate image of each type, so the browsers don't get confused when they ask for a jpg and you send them a gif. The RewriteRule I posted above does that - the $1 on the right side of the rule takes the value of whatever matched the parenthesized group on the left; If a gif is requested, a gif is returned, except that it is your special replacement gif for the hotlinkers. Same thing for a jpg request, your alternate jpg will be returned to hotlinkers.
I presume from what you are saying that you want other sites to be able to hot-link your images, just not that particular one. Frankly, I don't allow any hotlinking, so the code I posted says "If the referrer is not blank and that request was not referred from my site, then redirect it." By saying "not referred from my site" instead of naming a specific site, I avoid having to keep adding site after site as I discover other hotlinkers - It is a maintenance issue.
Note that if you are serving alternate images, you need to keep the file size small, otherwise you won't save anything on bandwidth. You can use the alternate image to say "this image stolen from www.mysite.com" or to play a trick on the thief "Special 2-for-1 offer - And FREE shipping on all merchandise!", etc. Or you can just block the request using the
RewriteRule \.(gif¦jpg)$ - [F] With mod_rewrite, it all depends on what you want to do - It's a very handy power-tool.
Jim