blocking inline images with mod_rewrite

blocking inline images with mod_rewrite

Post by mr_sca » Wed, 23 Oct 2002 18:43:50


I am testing out a situation where a remote webserver (serv1) hotlinks
an image (img1.gif) to my local server (serv2).  With mod_rewrite, I
wish to block it and send back a different one (img2.gif).  On serv2,
mod_rewrite has been tested with basic functionality (it is installed
fine).

From a doc on serv1, URIs to both img1.gif and img2.gif pointing to
serv2 work (no mod_rewrite at this point).

Now on serv2 I configure mod_rewrite:

Rewri*gine   on
RewriteLogLevel 2
RewriteLog      /usr/local/apache/logs/rewrite_log
RewriteRule     .+\.(gif|jpg)$     http://serv2/img2.gif     [R]

And on serv1 I point to img1.gif:

SRC = "http://serv1/img1.gif">

Results:

The page comes up but without any image.

The logs of serv2:

a) appended to access_log:

"GET /img1.gif HTTP/1.1" 302 237
"GET /img2.gif HTTP/1.1" 302 237

b) last line appended to rewrite_log:

redirect to http://serv2/img2.gif [REDIRECT/302]

c) nothing reported in error_log

Any ideas?  Thanks for any clues.

 
 
 

blocking inline images with mod_rewrite

Post by Sebastien LITAIZ » Wed, 23 Oct 2002 19:10:09


Hi!

Looks like you've done a loop... When you access img2.gif, your rewrite rule
matches and you redirect to the same url, at which point your browser,
obviously, doesn't do anything more. You have to make sure img2.gif doesn't
match your rule.

Sebastien
--
vrai compte / real account:
user: slitaize
domain: free.fr

Quote:> RewriteRule     .+\.(gif|jpg)$     http://serv2/img2.gif     [R]
> a) appended to access_log:
> "GET /img2.gif HTTP/1.1" 302 237
> b) last line appended to rewrite_log:
> redirect to http://serv2/img2.gif [REDIRECT/302]


 
 
 

blocking inline images with mod_rewrite

Post by mr_sca » Thu, 24 Oct 2002 04:49:00


On Tue, 22 Oct 2002 12:10:09 +0200, "Sebastien LITAIZE"

Quote:>Hi!

>Looks like you've done a loop... When you access img2.gif, your rewrite rule
>matches and you redirect to the same url, at which point your browser,
>obviously, doesn't do anything more. You have to make sure img2.gif doesn't
>match your rule.

Thank you for your answer.  I inserted a RewriteCond with a negated
REQUEST_FILENAME test and got it to work.
 
 
 

1. apache mod_rewrite question: blocking images

Hello,

In the URL Rewriting Guide is this example:

---------------------
Blocked Inline-Images
Description:
Assume we have under http://www.quux-corp.de/~quux/ some pages with
inlined GIF graphics. These graphics are nice, so others directly
incorporate them via hyperlinks to their pages. We don't like this
practice because it adds useless traffic to our server.

Solution:
While we cannot 100% protect the images from inclusion, we can at least
restrict the cases where the browser sends a HTTP Referer header.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
RewriteRule .*\.gif$        -                                   [F]

---------------------

Now is my question: I wanted to make this a more general piece, usable
for every site:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://%{SERVER_NAME}/.*$ [NC]
RewriteRule .*\.gif$        -                           [F]

But it doesn't work. Even on my site itself the images are blocked. Why
is this? %{SERVER_NAME} is a valid variable, isn't it?

I hope somebody can help me. Oh, I'm using Apache 1.3.24

regards,
Kevin Renskers
The Netherlands

2. Print jobs in SCO 'over-write' each other

3. mod_rewrite help please - blocking direct image linking

4. obtaining packages via ftp

5. mod_rewrite & image blocking?

6. Solaris PPP

7. blocking hotlinked images with mod_rewrite

8. X slows down with more ram (16 -> 32 mB)

9. Netscape and inline images

10. Know why WWW inline image is doubled?

11. Dobled-up inline images in Mosaic

12. Inline Images for Sun

13. Inline Images