Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite with opposite result

...has me puzzled

         

DrDoc

5:41 am on May 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I put this in my .htaccess file:

RewriteEngine on 
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com/ [NC]
RewriteRule \.(gifŠjpgŠpng)$ /img/no.$1 [L]
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com/ [NC]
RewriteRule \.(cgiŠphp)$ - [F]

Now... that should block any "hotlinkers" access to my graphics or scripts. But it when I load the home page I don't get any graphics :(

So, obviously something is wrong. I just can't figure out why...

jdMorgan

12:53 pm on May 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrDoc,

Several possibilities:

Try removing the trailing slash from "example.com" in the RewriteConds.
"example.com" must be your own domain.
Your browser may have cached the server response after you tested from a "foreign" domain.
If any subsequent redirects are processed (in lower-level directories, for example), you will have to explicitly allow access to the substitute image files in /img/no.gif, etc. by adding another RewriteCond.
Otherwise, your code looks fine.

Casual readers, please note that this board deletes spaces preceding exclamation points. These spaces are required in mod_rewrite. So, for example, the second RewriteCond above should read:


RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com [NC]

It also modifies the vertical pipe "¦" characters. Replace them with solid vertical pipe characters from your keyboard.

HTH,
Jim

DrDoc

5:04 pm on May 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm, it was the trailing slash. I could've sworn I tested without it too! LOL
Oh well, thanks :)

explicitly allow access to the substitute image

Aah... totally forgot about that. What would that rewrite rule look like?

Longhaired Genius

5:33 pm on May 10, 2003 (gmt 0)

10+ Year Member



Try this:
RewriteCond %{REQUEST_URI}!path_to_your_image/image.jpg [NC]

I allow access to everything in my "graphics" directory like this:
RewriteCond %{REQUEST_URI} !graphics/.*$ [NC]