Jump to content

Need help with stubborn hotlinking prevention rules


blacklotus

Recommended Posts

Okay... I'm getting really frustrated with this one and hope someone can help me.

 

I want to prevent hotlinking to images on www.vortexaviation.ca, and for this I'm using mod_rewrite (or at least I'm trying)

 

I have one image I want to use as a hotlink substitute (I want to show this instead of any image an external site would link directly). This is the image: http://www.vortexaviation.ca/images/nohotlinking.gif

 

(If you can see the image below and it's showing a NO HOTLINKING icon, it's working now... if it's broken, is not showing anything or you see a Flightstar logo, I still need help)

 

---> flightstarlogo_white.jpg <---

 

I read MANY tutorials on how to do it, and ended up with the following .htaccess file (located in my HTTP_ROOT)

 

Options +FollowSymlinks
# no hot-linking
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?vortexaviation\.ca/ [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule .*\.(gif|jpg|png)$ http://www.vortexaviation.ca/images/nohotlinking.gif [NC]

 

It's blocking the image fine, but it won't replace it with my substitution! All it does is create a broken image icon.

 

You can see a test I'm doing from another one of my sites at http://vortexaviation.black-lotus.net/test.php

 

The image should appear above the "Test referer" link (which directs to another page so I can debug the HTTP_REFERER string).

 

Can anyone see something wrong? Would there be something not enabled on my server? I'm using the Economy Linux Hosting plan from godaddy.com and the domain is not a subdomain.

I FIXED IT!

 

The code I was using was creating an infinite redirect loop. So I added a RewriteCond to exclude the nohotlinking.gif file...

 

It's sad no tutorial I read about mod_rewrite said anything about that problem though...

 

This is my final code:

 

Options +FollowSymlinks
# no hot-linking
RewriteEngine On
RewriteCond %{REQUEST_URI} !nohotlinking.gif$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?vortexaviation\.ca/ [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule .*\.(gif|jpg|png)$ http://www.vortexaviation.ca/images/nohotlinking.gif [R,NC]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.