Forum Moderators: phranque
#prevents hotlinking and returns stolen2.gif
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.com/ [NC]
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ /images/stolen5.gif [L]
I replaced the broken pipes and inserted a space before the quotation mark.
Could the problem be that the images that are being hotlinked are in a number of subfolders under /images/? Should the code be different in this case?
bandwidth costs last month were excessive and I need to find a way to fix this as soon as possible as I'm already over again this month. Thx for help!
In order to prevent this, add a RewriteCond:
#prevents hotlinking and returns stolen2.gif
RewriteCond %{HTTP_REFERER} [b].[/b]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.co[b]m[/b] [NC]
RewriteCond %{REQUEST_URI} !^/images/stolen5\.gif
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ /images/stolen5.gif [L]
The second, removing the trailing slash from your domain, will prevent a problem when there is a port number appended to your domain, something which can be done by caching proxies without the visitor being aware of it. Example: www.mydomain.com:80/image.gif is perfectly valid, but would cause your original RewriteCond to fail.
If you are a stickler for precision, the following Cond would specifically handle both cases, while insisting that the tld be exactly ".com" and that the trailing slash be present:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com(:[0-9]{1,5})?/ [NC]
Jim
Thanks Jim, I tried both, but neither worked.
cleared cache in three browsers, closed 'em and tried again.
In fact, I've tried all of five below (chronolgically) making sure all broken pipes fixed and all spaces added :(
#prevents hotlinking and returns stolen5.gif
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.com(:[0-9]{1,5})?/ [NC]
RewriteCond %{REQUEST_URI}!^/images/stolen5\.gif
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ /images/stolen5.gif [L]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.com [NC]
RewriteCond %{REQUEST_URI}!^/images/stolen5\.gif
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ /images/stolen5.gif [L]
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.com/ [NC]
RewriteRule \.(gif¦jpg)$ /stolen5.gif [R,NC]
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mydomain.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ /stolen5.gif [R,NC]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.com/ [NC]
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ /images/nohotlink.jpg [L]
I have some other errors in the error log, but if I use a 301 to redirect a hotlinked image (lower down ion htaccess than the code below) it works.
these are two of the other errors both the same IP:
.htaccess: RewriteCond: cannot compile regular expression '^65\.x x x\.41\.(19[2-9]¦2[01][0-9]¦22[0-3]'
.htaccess: Invalid command 'R', perhaps mis-spelled or defined by a module not included in the server configuration
P.S. thanks for reminding me of wannabrowser the other day. It helped better than using firefox's UA agent - sent a nice contribution, too!
The first error in your log file is because of a missing closing parenthese on the IP address alternatives.
The second one looks like you must have a typo, with one line in your file starting with "R".
If the code I posted above doesn't work, it is not because of an error in that code. (Sorry to sound like I have a fat head, but the code is correct as posted.)
Jim
I cecked and I had the closing paren on the IP line in my htaccess, I just copied what showed in the error log and it ended as shown without the last bit and the paren -and- there is no line starting with just an R and no misspelling of any word beginning with an R (did a mass replace of each 'R' word, one letter at a time to be sure I didn't miss a misspelled word). Have NoteTab ramped up to font size 16 (per one of jdmorgan's previous suggestions). After hours of looking I can't find a single error in spelling, closing quotes, brackets, spaces, etc.
One other "anomaly". I 301'd to stolen5.gif about 30 images that are hotlinked in a kiddie forum. Then, so I could check to see if the code was working, I un-301'd one of them and after 8 hours, cache clearing and even rebooting, it is still showing the stolen5.gif where it should now show the actual image.
Ah, well I'll keep looking. Thanks for all your help Jim!