Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite and java applets

         

SilentMoon

9:18 am on Mar 4, 2004 (gmt 0)

10+ Year Member



I have used mod_rewrite to protect image hotlinking, it also stops java applets from loading the image even when the image is in the same folder as the applet. I have spent several hours searching for a way around this other than removing hotlink protection and have only came across others having the same problem. It is not loading the nohotlinking.png either it just never loads. Anfy and DS applets are the ones that are having issues. At the moment I am being forced to use mod_rewrite in the other folders that do not contain the applets instead of at root level.

The code I attempted to use at root level is:


RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦css¦ani¦js¦pl¦php)$ http://www.mysite.com/error/nohotlinking.png [R,NC]

I have also noticed that it prevents some of the php scripts that open results in a new window from working, showing the nohotlinking.png instead.

Thanks
Moon

jdMorgan

9:52 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SilentMoon,

Welcome to WebmasterWorld [webmasterworld.com]!

HTTP referrers are unreliable.

Client-side scripting languages generally do not provide a referrrer.

Therefore, you'll need to add

 RewriteCond %{HTTP_REFERER} . 

to the top of your list of RewriteConds.

Actually *all* of your RewriteConds can be replaced by these two lines:


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

without changing the RewriteRule behaviour.

Unfortunately, allowing blank referrers will allow right-click-save and direct browser address bar type-ins to access your images, but there's not much you can do about it, short of using authentication, sessions, or cookies.

Jim

SilentMoon

1:55 am on Mar 6, 2004 (gmt 0)

10+ Year Member



Thank you for your reply, what I ended up doing is block hotlinking at root level for the images, then in each folder that contained an applet making a new htaccess to allow it for those folders only. It seems more efficent this way since the root htaccess also contains banned ips etc. and only a couple of folders contain applets.
Thanks again
Moon