homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

Using .htaccess to prevent image linking

 4:11 pm on Sep 1, 2003 (gmt 0)

I've been reading other posts about how to prevent image linking via .htaccess. I've read through a lot of the other topics on here but none of them seem to help. I'm currently using this script:

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

I've tried to change the RewriteRule several different ways to use a specific image instead of the blank image line, most commonly variations of:

RewriteRule \.(gif¦jpg)$ [mysite.com...] [R,L]

However, this doesn't work. After changing this, I found that people could still view my image (I did clear my cache).

Any suggestions? I do have mod_rewrite.

Also, if I wanted to change this script to allow one folder from my site to be directly linked (I'll need to do so for ebay auctions), does anyone have a suggestions?

Thanks for any help.



 4:56 pm on Sep 1, 2003 (gmt 0)

Hi smirkl,

I set my site up to block image linking when I realised some forum junkie was using four in his sig! Took me a fair while to get it working correctly but here it is:

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

Hope that helps


 5:21 pm on Sep 1, 2003 (gmt 0)

I just ran into something early this morning I hadn't noticed before.

There was (another) forum whose member added an image that was a 200px square stating "This is a Stolen Image."

Obviously, the image was still draining bandwidth, but it certainly got the point across: Don't Steal My Images! [and made the member look like an idiot].

Apparently any image located at a different address is swapped with the alternate image. Interesting trick.


 5:30 pm on Sep 1, 2003 (gmt 0)

And if you right click >> properties on that image, Netguy, it will still show the path to the original image the bandwidth theif linked to. It must really confuse amature web users!

For my site I just made up a quick banner ad with my url and some graphics to gain a little free exposure in return for the bandwidth taken. Fair trade IMHO.


 5:35 pm on Sep 1, 2003 (gmt 0)

be wary be very wary ..

I post on some photography forums and someone else who also does found some people stealing his images ..

He pointed his camera down a toilet and took an image of what he found there.

Then he used this code to serve that image whenever anyone off his domain requested images from his server ..

When I saw them in the forum where I post .. (where he had posted his own images) I wrote .. w-t-f are you doing ..

Ooops came the embarrased reply I forgot about my own postings of images .. better change that immediately :-)

You can selectively redirect I am pretty sure

so either only offenders image requests are changed ..

or .. you permit yourself to post your images on particular domains ..

Anyhow his linked image was not nice ..
Hope it amuses :-)


 6:44 pm on Sep 1, 2003 (gmt 0)


Fixing up your code:

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

Note that the "¦" character is modified by posting on this forum. You will need to use the solid vertical pipe character from your keyboard - usually Shift \ on U.S. keyboards. Also, spaces preceding "!" are deleted by this forum; type two spaces when posting if you want one to show.



 2:13 pm on Sep 2, 2003 (gmt 0)

Thanks Jim!

I think that the pipe code bit helped me figure out part of the problem (the main one was that the .htaccess code was actually blocking the image I wanted to change it with as well as the others, which was really stupid of me).

Now to experiment with a .htaccess blank referrer to see if using just that will override the .htaccess the folder above ...


 3:46 pm on Sep 2, 2003 (gmt 0)


Just be aware that many legitimate users will have a blank referrer - that is why it's allowed in most of the code you see here. Any user who comes through an ISP or corporate proxy, or who uses Norton Internet Security may have a blank referrer. You'll have to decide whether losing them is worth the cost of blocking blank referrers.

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved