Forum Moderators: phranque

Message Too Old, No Replies

HTTP_REFERER - Replacing Image with Generic GIF Problem (httpd.conf)

         

yoyo8

11:45 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



This is the entry in the log:

"GET /drawing/user-name/draw123.jpg HTTP/1.1" 302 307 "http://chat9.terra.com.br:23137/xx?ImagensDiversos&Diversos+1&VANONIMO___&-1&97c6a5e241019e19124e1805a831c" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MSN 9.0; MSNbMSNI; MSNmen-us; MSNcOTH)"

So it's not blocking the image because of the 302, right?

This is what I have in the httpd.conf file:

<Directory "/home/site/mysite/drawing">
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite\.com [NC]
RewriteRule \.(jpg)$ [127.0.0.1...] [R,NC]
RewriteCond %{HTTP_USER_AGENT} ^HTTrack [OR]
RewriteCond %{HTTP_REFERER} ^http://chat9\.terra\.com\.br [NC,OR]
RewriteCond %{REMOTE_ADDR} ^84\.128\.6\.37
RewriteRule!404\.php$ - [F]
</Directory>

What am I doing wrong? Thanks.

jdMorgan

12:03 am on Jul 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yoyo8,

> So it's not blocking the image because of the 302, right?

Possibly...

You don't need a redirect unless your substitute image is not on this server. Try an internal rewrite instead of a redirect:


RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
RewriteRule \.jpg$ /drawing/stuff/logo.gif [NC,L]

This simply substitutes the file at /drawing/stuff/logo for any .jpg image requested with a non-blank referrer that is not your own domain.

The [L] flag will stop mod_rewrite processing if the rule matches and the rewrite is invoked. There is usually no need for further mod_rewrite processing, so use [L] unless you have a reason not to use it. The [F], [G], and [P] flags all include an implied [L], so you don't need it there (such as in your second rule).

Another likely cause of trouble is that the requested image may already be stored in your browser cache. Therefore, the request is never sent to your server, so your code cannot have any effect. Be sure to flush your browser cache before testing any new rewrite or redirect code. Otherwise, you will get unexpected results.

Jim