Problems w/ .htaccess (preventing hotlinking)

Problems w/ .htaccess (preventing hotlinking)

Posted by: daisygirl
Posted on: 2005-03-14 10:57:00

A search didn't turn up anything about my particular issue, so I'm hoping someone can give me some advice...

I added this to the .htaccess file in my site's root directory:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?daisywreath.net(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?p084.ezboard.com(/)?.*$ [NC]
RewriteRule .*.(gif|jpg|jpeg|bmp)$ http://daisywreath.net/pixel.png [R,NC]

I've tested this, and I'm getting bizarre results. I generated the code here: http://www.htmlbasix.com/disablehotlinking.shtml and I'm using their tester to test whether it's working or not. I cleared my cache before testing & have tested a few images in various places on my site.

When I try to remotely load images from http://daisywreath.net/pics/ -- it works, I get the 1-pixel transparant image I specified.

When I try to remotely load images from http://daisywreath.net/crochet/ or any of its subdirectories -- the image loads anyway. I've cleared the cache, uploaded a random new image from my hard drive that couldn't possibly have been in the cache, etc.

The /crochet/ directory has its own .htaccess file to specify its own 404 page and some rewrite rule whose purpose I can't quite rember, something to do with Wordpress. Do I need to copy this info to any other .htaccess files I have in any subdirectories? I thought subdirectories inherited rules from .htaccess files in parent directories--am I wrong here?

Edited by daisygirl on 03/14/05 10:58 AM (server time).

Re: Problems w/ .htaccess (preventing hotlinking)

Posted by: decswxaqz
Posted on: 2005-03-14 11:02:00

Directories with their own htaccess won't inherit higher level htaccess files (I think). Because if it gets conflicted rules, it'll die =/. So you should copy/paste the code from your root file to your other htaccess file.
Thinks that's your problem *-)

Re: Problems w/ .htaccess (preventing hotlinking)

Posted by: daisygirl
Posted on: 2005-03-14 11:11:00

Thanks--I'll fix that. I read on some site earlier today that it would inherit it even if there was another .htaccess file, so I was scratching my head over this. Fortunately only this directory has its own .htaccess so shouldn't be too much hassle to keep updated separately.

Re: Problems w/ .htaccess (preventing hotlinking)

Posted by: decswxaqz
Posted on: 2005-03-14 11:27:00

In reply to:

The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.



http://httpd.apache.org/docs/howto/htaccess.html

You are right. But I guess if it's only in one folder, and editing the file works, just stay with that option.

Re: Problems w/ .htaccess (preventing hotlinking)

Posted by: daisygirl
Posted on: 2005-03-14 12:06:00

How strange that it wasn't working, then... Changing the .htaccess in the subdirectory did fix it, though it turns out it's a bit more work than I thought because I found a second subdirectory that also has its own .htaccess and was ignoring the one in the parent directory. Oh well, least it's working now!

Tags: htaccess filejpeg bmpjpg jpeggif jpgezboardroot directoryhotlinkingpngshtmlpixelhopingcachehttp