From: Barely Audible on
I am trying to prevent hotlinking of my images and using the following
script on my SUSE 11 server

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://mysite.com/hotlink.gif [L]

It isn't working correctly for some reason - can anyone tell me why?

--
TTFN
Jim

When you have sufficient supplies and ammo, the emeny takes 2 weeks to
attack. When you are low on supplies and ammo, the enemy decides to
attack that night.
-- Murphy's Military Laws, #51
From: Barely Audible on
houghi wrote:
> Barely Audible wrote:
>> I am trying to prevent hotlinking of my images and using the following
>> script on my SUSE 11 server
>>
>> RewriteEngine On
>> RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
>> RewriteCond %{HTTP_REFERER} !^$
>> RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://mysite.com/hotlink.gif [L]
>>
>> It isn't working correctly for some reason - can anyone tell me why?
>
> Sorry, no idea. But perhaps better ask it in a Apache related group as
> there will be more people who know the answer.
>
> And as an extra, if you do not want to use your websites name, use
> example.com.
>
> houghi


Blimey Houghi - you are the one poerson I expected to get a reply from! ;-)


--
TTFN
Jim

There is no problem that cannot be solved by the use of large
quantities of high explosives.
From: David Bolt on
On Wednesday 31 Mar 2010 20:44, while playing with a tin of spray paint,
Barely Audible painted this mural:

> I am trying to prevent hotlinking of my images and using the following
> script on my SUSE 11 server
>
> RewriteEngine On
> RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
> RewriteCond %{HTTP_REFERER} !^$
> RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://mysite.com/hotlink.gif [L]
^^^
You don't have a R here which you may require since you're specifying a
link to an external site, even if it's really the same site.

> It isn't working correctly for some reason - can anyone tell me why?

Now, what's the actual error? Are you getting a "500 server error"? If
so, probably haven't allowed rewriting in the server configuration
and/or enabled mod_rewrite.

As an example, I've added a .htaccess to my site for testing. The
contents is:

davjam(a)moray:~/public_html/test> cat .htaccess
RewriteEngine on

# test to see if images are pinched from elsewhere
#
RewriteCond %{HTTP_REFERER} !^http://(www\.)?davjam.org$ [nc]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?davjam.org/.*$ [nc]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://www.google.com/ [nc,r,l]

davjam(a)moray:~/public_html/test>

And a quick test of it returns the expected redirect to Google:

davjam(a)moray:~/public_html/test> curl -x '' -A '' -v http://www.davjam.org/~davjam/test/test.jpg
* About to connect() to www.davjam.org port 80 (#0)
* Trying 192.168.0.40... connected
* Connected to www.davjam.org (192.168.0.40) port 80 (#0)
> GET /~davjam/test/test.jpg HTTP/1.1
> Host: www.davjam.org
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Wed, 31 Mar 2010 21:33:28 GMT
< Server: Apache/2.2.4 (Linux/SUSE)
< Location: http://www.google.com/
< Content-Length: 289
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://www.google.com/">here</a>.</p>
<hr>
<address>Apache/2.2.4 (Linux/SUSE) Server at www.davjam.org Port 80</address>
</body></html>
* Connection #0 to host www.davjam.org left intact
* Closing connection #0



Regards,
David Bolt

--
Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s
openSUSE 11.0 32b | | | openSUSE 11.3M3 32b
openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11