Forum Moderators: not2easy

Message Too Old, No Replies

Question about preventing hot-linking

         

thecoalman

1:53 pm on May 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month


If I use this code in htaccess it should not only prevent other sites from linking to my images but also provide the alternate image nasty.gif

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ http://www.mydomain.com/nasty.gif [R,L]

My question is this, If I change nasty.gif to index.html will it cause the browser to serve up my homepage if I have the following script in my head tag for index.html.

if (window!= top)
top.location.href=location.href

I know this script will prevent sites from framing my site as I have tested it. Also if anyone has any comments on using this script for preventing framing please post them.

jdMorgan

2:32 pm on May 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thecoalman,

Welcome to WebmasterWorld [webmasterworld.com]!

Unfortunately, browsers will not properly follow a redirect from an image-format file to an html-format file; all you'll get is a "broken image" graphic where the original hotlinked image was.

The two methods that will work are replacing the image, as the code you posted does, or simply returning a 403-Forbidden response as shown below, which again shows the "broken image" graphic, but places less load on your server.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com/ [NC]
RewriteRule \.(gif¦jpg)$ - [F]

HTH,
Jim

thecoalman

5:08 pm on May 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the speedy reply.