Forum Moderators: phranque

Message Too Old, No Replies

rewrite redirection causing loop

redirecting is causing a loop

         

waveking

2:18 am on May 16, 2006 (gmt 0)

10+ Year Member



Hi,
I am simply trying to prevent hotlinking of the images on my server. I wish to replace the hotlinked images with a specific image i have on my server

my htaccess is:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://(.+\.)?mysitehere\.com/ [NC]
RewriteCond %{HTTP_REFERER}!^$
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ /images/stolen.png [R,L]

Mokita

2:35 am on May 16, 2006 (gmt 0)

10+ Year Member



The looping problem is most probably caused by you redirecting the request to an image contained within the domain and/or folder that you have protected from hot-linking.

There are two possible solutions that I can see.

1) Remove the anti hot-linking code from the .htaccess file for root and instead place it in your /images/ folder and then move the "stolen.png" to root or another folder.

2) Convert the "stolen.png" to an image type that you are not attempting to protect e.g. stolen.tif

jdMorgan

2:47 am on May 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can exclude the replacement image from being redirected by adding a negative RewriteCond:

RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysitehere\.com/ [NC]
RewriteCond %{REQUEST_URI} !^/images.stolen\.png
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ /images/stolen.png [R,L]

(plus a few minor tweaks for efficiency)

Jim

[edited by: jdMorgan at 3:46 am (utc) on May 16, 2006]

waveking

2:58 am on May 16, 2006 (gmt 0)

10+ Year Member



Thanks Mokita and jdMorgan!

Mokita, I moved the rules to the specific folder which i needed to protect, while keeping the stolen.png in a separate folder...and it works great now!

jdMorgan, what "effeciency tweaks" are you hinting at?