Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite infinite looping on anti-image leech directive

plus, the directive isn't working as intended

         

intellivision

6:04 pm on Jul 1, 2009 (gmt 0)

10+ Year Member




RewriteCond %{HTTP_REFERER} !^http://(.+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g夙if在mp如ng)$ http://www.example.com/images/hotlink.gif [NC,L]

That's the first directive in my .htaccess file at site root.

Here's the server log error:


[Wed Jul 01 11:04:16 2009] [error] [client 192.168.0.1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary., referer: http://www.otherdomain.com/page.html

[edited by: jdMorgan at 6:42 pm (utc) on July 1, 2009]
[edit reason] Formatting, example.com [/edit]

intellivision

6:05 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



fixed the code tags, thanks g1smd!

[edited by: intellivision at 6:43 pm (utc) on July 1, 2009]

g1smd

6:26 pm on Jul 1, 2009 (gmt 0)

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



Use [ code ] and [ /code ] but without the spaces. :)

There's still time to edit the post. Click "edit".

Your rule redirects to a new URL, with a 302 redirect (because you included a domain name). Are you sure that you didn't want a 301 redirect, or even an internal rewrite?

You have an infinite loop because the redirect to the .gif matches the pattern again and so redirects again - forever.

There was a very detailed thread on the same topic just over a week ago. That one is very well worth reading. I'll try to find a link.

intellivision

7:44 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Victory!


RewriteCond %{HTTP_REFERER} !^http://(.+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/images/hotlink.gif$
RewriteRule .*\.(jpe?g夙if在mp如ng)$ /images/hotlink.gif [NC,L]

I excluded the replacement image and shortened the URL, eliminating the domain bit. Thanks to g1smd.

jdMorgan

10:05 pm on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can shorten/speed that up a bit:

RewriteCond %{HTTP_REFERER} !^(http://([^./]+\.)*domain\.com\.?(:[0-9]+)?/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/images/hotlink.gif$
RewriteRule \.(jpe?g夙if在mp如ng)$ /images/hotlink.gif [NC,L]

Jim

[edited by: jdMorgan at 10:06 pm (utc) on July 1, 2009]

intellivision

10:26 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Super, thanks Jim. Done.