htaccess- anti-leeching

Question
i tried to use the below code in a specific folder (non watermarked images)
and it didn't work, it changed all my images to the "restricted" image.
?
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://yousite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yousite.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ http://www.yoursite.com/restricted.gif [R,L]
code is from:
http://www.simcoweb.com/am/publish/article_7.shtml

Answer
Try this.... FULLY commented as to what it does..
Code: # If no http_referer, like requesting your image directly by typing to full URL to # image, continue it to the next condition RewriteCond %{HTTP_REFERER} ^$ [OR] # If it has http_referer but it doesn't match http://www.domain.com or # http://domain.com, then stop now and apply the rule # If you have other sub domains at http://*.domain.com, change # it to !^http://([www\.]*)domain\.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://(.*)domain\.com/.*$ [NC] # Choose either rewrite rule #1 or #2 below # 1) serves a [403] for image.gif, .GIF, .jpg, .JPeg, # or image.JPEG files RewriteRule .*\.([gif|jpe?g]+)$ - [NC,F] # # OR # # 2) uncomment THIS line instead to redirect their hot links back # to your main page! (or some other page/image) #RewriteRule /* http://www.mydomain.com/index.html [R,L] You will notice some differences from what you have..
-Jim

Answer
Originally Posted by www.imosh.com RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://yoursite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ http://www.yoursite.com/restricted.gif [R,L] Also note that such .htaccess code is intended for Apache servers. There are loads of other code snippets to keep out the script kiddies and assorted nasties.
© 2007 www.aqcollection.com | Contact us |