Forum Moderators: phranque

Message Too Old, No Replies

Rewrite to Protect Images not working

It used to!

         

carfac

3:06 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi:

I use the following code in httpd.conf to protect images in some directories. It USED to work, but now does not seem to be... anyone have any ideas?

### Protect Local Images
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule (gif¦jpg¦JPG¦GIF)$-[F,L]

BTW, I checked my apache logs during testing, and I AM passing the reffer field... from the log:

My.IP.it.me - - [26/Aug/2003:09:04:38 -0600] "GET /images/users/693-user_icon.jpg HTTP/1.1" 200 10579 "http://site.using.my images" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02"

Dave

<edit> whoops- my domain name slipped in!</edit>

carfac

3:55 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi:

I figured it out- kinda freaky.

I was using the rewriterul inside a directory area- I just wanted it to protect the images subdirectory (as I do have some public images I keep elsewhere, and I do not want to block those!) So, anyway, that did not work. But when I moved the rewriterule to the base directory, it worked.

So, I changed the code to:

RewriteRule ^/images/.*(gif¦jpg¦JPG¦GIF)$-[F,L]

and that worked!

I do not know if have an option off I need on in the <DIRECTORY /path/to/my/images> area (I did try turning on +FollowSymLinks, no go!)...

dave

piramida

10:19 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



nitpicking, I am, but you can better write it as

RewriteRule ^/images/.*(gif¦jpg)$ - [F,L,NC]

:)

FollowSymlinks should have helped... does your global conf prohibit overriding these values?

jdMorgan

10:42 pm on Aug 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nitpicking some more, youi don't need [L] with [F] - it's built-in.
And RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC] can be shortened
to: RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/ [NC]

:)
Jim