homepage Welcome to WebmasterWorld Guest from 54.167.138.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Image Hot Linking
Disallow Hot linking from a specified folder.
TheKiller



 
Msg#: 4331033 posted 5:25 pm on Jun 25, 2011 (gmt 0)

Hey there, well i have a folder where i am keeping banners, for others to link at. I Would like to disa allow them linking to them directly, and like them to place the banner on their site, so i wont have to contact each of them, after i decide to switch the paths.

This is the path of my banners:
http://www.example.com/Files/SitePictures/BannerV1/
I Would like to Disallow Hot linking from the BannerV1 Folder.

I have tried this, but it seems to work only if i put it into the Root folder.


RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?example\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://img148.imageshack.us/img148/237/hotlinkp.gif [L]

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4331033 posted 9:17 pm on Jun 25, 2011 (gmt 0)

I have tried this, but it seems to work only if i put it into the Root folder.

Some servers only let you put the .htaccess in the top level, so this may be out of your control. Or you may need to change a setting. Do you have any other directory-specific .htaccess files? Do they work as intended?

Are you trying to set up a rule that says it's OK to hotlink other images, just not the ones in the "banners" directory? Honestly, it's easier to put down a blanket ban, and then add exceptions for the sites you personally approve. Hotlinks annoy the ### out of me on principle, even though I don't pay for bandwidth so they're not costing me anything. Personally I'd just leave it in the root, especially when you know it works.

In any case you don't need .* at the beginning of an unanchored string, so you can delete that bit without changing anything else.

TheKiller



 
Msg#: 4331033 posted 2:37 am on Jun 26, 2011 (gmt 0)

I Dont know if i can, as i moved to a new host. But i have Contacted them and asked if it may be a server issue.

Yes, i dont host too many images on my domain, so i dont care what images they link to. I Just Dont want them to link to the contents of that Folder.

There arent any sites that are approved to link from there..
What is that " .* " for?

I got that script from here [altlab.com...]
Dos it specify the extension for all images ?

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4331033 posted 7:40 am on Jun 26, 2011 (gmt 0)

.* means "there might be some stuff here". Since the rule is only concerned with the extension, it doesn't matter what comes before it.

You don't need to list all possible extensions, just the ones you've actually got. The main three are .gif, .jpe?g and .png. If you really have .bmp format (Windows bitmap?) you should add it, just as you might add .pict or .svg or .jp2 or anything else you've got lurking in the directory. But if they're banners they probably all use the same extension anyway.

To be safe, add an NC to the rule, in case someone asks for JPG.

TheKiller



 
Msg#: 4331033 posted 4:58 pm on Jun 26, 2011 (gmt 0)

@Lucy, it seems that My host approves .htaccess files in other folders than the root. My Host Staff told me its a Script issue. Do you have any idea how to make it work only for that folder? Dos it have to do with the referer specified in the code?

I got the main 3 more.. and in some cases bmp i guess... But is there a speed problem if i add them all, just for being sure?

Can you help with ficing the script for that folder only, and not the root

TheKiller



 
Msg#: 4331033 posted 6:00 am on Jun 27, 2011 (gmt 0)

wohoo...

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4331033 posted 8:13 am on Jun 27, 2011 (gmt 0)

Directory-specific .htaccess is outside my area of expertise. (Actually, htaccess in general is o. my a. of e., but I speak pretty fluent RegEx, which is 90% of most questions.) I've got one directory with its own htaccess calling on a directory-specific error document, and find with interest that it says

ErrorDocument 404 /paintings/nopage.html

even though we are already inside the /paintings/ directory.

I have no idea what your hosts mean by "script issue". It would not surprise me to learn that they don't either. Your rewrite as originally written ought to work. When testing, did you do the routine stuff like clear your browser cache so it isn't feeding you a pre-existing copy of the image?

TheKiller



 
Msg#: 4331033 posted 7:45 pm on Jun 27, 2011 (gmt 0)

?
htaccess is server side ... i doubt it has effect with my browser cache. if i switch the code to the root directory i cant see them

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4331033 posted 9:07 pm on Jun 27, 2011 (gmt 0)

I mean that if you've already got an image cached, and you're testing your hotlink routine, your browser may simply give you the cached copy instead of asking the server for a fresh one. An even worse scenario is when your ISP (not your site host, your personal ISP) does its own remote caching. Sometimes they'll reload on request; sometimes they won't bother.

So when you're testing things, make sure to test using a brand-new filename that can't possibly be cached anywhere.

Oh, and I only just noticed that your original code starts with .* You can toss that part; all you're matching is the extension.

.jpe?g .gif .png are the only formats guaranteed to be recognized by all browsers. (Except lynx, duh, and let's not talk about MSIE 5.) So there's no reason to take up more computer time looking for stuff it will never find anyway. Remember, this is your own site so the extensions are under your control. You're not checking for everything that someone, somewhere might have put up because they don't know what they're doing. (Like the local rental agency that had all their graphics in AOL-proprietary format. Really.)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved