Forum Moderators: phranque

Message Too Old, No Replies

can anyone help

why doesn't this work?

         

Tattyfan

5:29 pm on Dec 29, 2003 (gmt 0)

10+ Year Member



I've been hot linked on my web site to the point where they are about to shut me down, i've searched the net and found out about htaccess (i'm only a beginner at this stuff) i put this code into my root directory

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mydomain.com/.*$ [NC]
RewriteRule .*[Gg][Ii][Ff]$¦.*[Bb][Mm][Pp]$¦.*[Jj][Pp][Gg]$¦.*[Jj][Pp][Ee][Gg]$¦.*jpeg$ [mydomain.com[R,NC]...]

apart from now linking to my site its not stopping the leaching can anyone tell me why i'm doing wrong?

jdMorgan

8:46 pm on Dec 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tattyfan,

Welcome to WebmasterWorld [webmasterworld.com]!

First, let's clean it up a bit and see if that helps. You've got two identical lines in there, and the Rule itself is, um, messy... ;) Also, you cannot redirect from an image file to an html page - it won't work, and would just use up your bandwidth anyway, even if it did work.


RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(gif¦bmp¦jpe?g)$ - [NC,F]

This will allow any non-blank referer from mydomain.com or www.mydomain.com full access, and block requests for gif, jpg, jpeg, or bmp files from any domain other than your own. Both the domain check and the filetype check are case-insensitive due to the NC (No Case) flag. A 403-Forbidden error will be returned for all such attempts, so make sure your custom 403 error file is small (if you have one).

Change all broken pipe "¦" characters above to the solid pipe character before use -- usually, it's Shift - \ on your keyboard.

If this doesn't help, please repost and say what it does and does not do. Remember to flush your browser cache (Temporary Internet Files) while testing. (If an image is already in your cache, then it will appear that your access was not blocked, because the image will be loaded from your local cache, and not from your server. If the image is not requested from your server, then .htaccess can't block it.)

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

Tattyfan

10:38 am on Dec 30, 2003 (gmt 0)

10+ Year Member



thanks for the reply, i have made the changes you said and now need to see if it works, but this morning the site was down due to exceeded bandwidth. Am i right in thinking that the .co.uk comes after the \
just to check i copy the code into notepad and name it htaccess.txt and upload to my root directory then remane to .htaccess (then it disappears)

thanks again

jdMorgan

4:30 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TattyFan,

> Am i right in thinking that the .co.uk comes after the \?

Well, yes and no...

Any time you want to match a literal period in regular expressions notation, you must precede it with a backslash, otherwise, a period means "any single character". The "^" character is a "start anchor" and thus requires an exact match at the beginning of the string being compared against the pattern. Similarly, the "$" character is an end anchor, requiring an exact match at the end of the pattern. Using both anchors specifies an exact string-to-pattern match, nothing more, nothing less. Thus, the URL "http://members.widgetclub.co.uk/login.php" would be written as "^http://members\.widgetclub\.co\.uk/login\.php$". The pattern I gave you in the post above intentionally omits the end anchor in the RewriteCond testing the referrer, and uses only the end anchor in the RewriteRule.

Follow the link I cited above and look for the link to the regular expressions tutorial cited in that post; Using mod_rewrite without a thorough understanding of regular expressions syntax and notation can be extremely frustrating, and possible dangerous to your site (Said with your best interest in mind and apologies for the apparent bluntness of communication in this medium).

Please let us know how this works out. If you still have problems, please try to capture the relevant log entries from your server error log -- they are often of great help in figuring out the exact problem.

Jim

Tattyfan

8:05 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



thanks for replying again Jim but all that went straight over my head :-(
i'm unable to do anything until the start of the month but i'll try then and see what happens. if i still get problems i'll post back.

Tattyfan

11:41 am on Jan 2, 2004 (gmt 0)

10+ Year Member



Hi Jim,
Thanks for the help with the code i uploaded it and it seems to be working. It now comes up with a forbidden message on any image copied and pasted from my site. :0)

To be really cheeky is there a way of locking images within front page? to stop the being taken in the first place.

thanks again

tattyfan

jdMorgan

5:36 pm on Jan 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TattyFan,

> is there a way of locking images within front page - to stop them being taken in the first place?

No, anything you post on the web can be abused. The idea is just to make it more difficult, so that most troublemakers will move on to easier targets. If you don't want it copied (at all), don't put it on the Web.

Interestingly, I got "attacked" last night for the first time in several years - hundreds of image requests for two images hot-linked from a discussion forum for one of the two most popular video-gaming consoles. Thankfully, after several hundred 403 errors over the course of an hour, the poster finally figured out that his post was showing broken images and de-linked them -- The log files are a mess!

On a more popular site, this could have been a real problem. So, the anti-hotlink code worked on my end... Glad it worked for you, too!

Jim

Tattyfan

1:09 am on Jan 4, 2004 (gmt 0)

10+ Year Member



mine seems to be working ok and i'm estimated to only use a 1/3 of my allowance this month, which is great news.
Glad yours worked i find it very sad that people that feel the need to pinch stuff or at least hot link it in the first place.
Thanks again for you help its been invaluable.
kayleigh