.htaccess 404 tracking from where

Busy's picture

He has: 6,151 posts

Joined: May 2001

My logs are showing a few not found errors but doesnt say where from etc and I know I can use .htaccess to create my own error pages but here is the tricky part, I have 5 web sites on one domain, one in the main directory and four off that, can I safety place an .htaccess file in each folder without it affecting the others? Also I want to disallow hot linking, would I have to include this code on every .htacces file or just the one in the main directory?

Since I doubt my logs will tell me exactly what happened I am thinking of making my error page email me the error with url it came from (dont want to add to db and can't use write to flat file), but HTTP_REFFER isn't work on links with ?'s say I have mainpage.php?page=1&day=2 all I'm getting is mainpage.php

Anyone know what I'm going on about Smiling and have any ideas how I can do what I want to do?

They have: 447 posts

Joined: Oct 1999

apache logs should tell you the url of the requested file that was not found.

also, you said it was 'a few' 404s. If it's just a few, it's probably people typing in the wrong url, or with outdated bookmarks, or hotlinks to images that have been deleted or moved. 404's are normal, you can't really prevent them. All you can do is make sure your own documents dont link non-existent files. I wouldn't worry about it unless it's much more than a few.

As far as your question, i'm far from an apache expert but i do know putting an .htaccess file in every directory is bad news. Apache has to parse every .htaccess file in every directory leading to the requested file, every time it's requested.

He has: 1,016 posts

Joined: May 2002

Actually, you can prevent hot-linking with .htaccess, I can give you the lines if you want to.

Busy's picture

He has: 6,151 posts

Joined: May 2001

problem with log files is they are cleared every few days, seems to get to about 2 mb then wiped, lately been having a lot of crawling and site saving going on (people using programs to download the whole site), added a robots file to block the known ones, will have to wait and see what happens.

as for the htaccess file, I have:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?munchtech.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.munchtech.com/humour4u/blank.gif [R,L]

this file (.htaccess) is in the folder the images are being linked from. just had a thought, would the htaccess file be better served in the main directory rather than the folder of the images being linked?
because linking to any image still displays it

They have: 447 posts

Joined: Oct 1999

hey Busy, i just checked out your HTML site for the first time and it looks like you really did a very good comprehensive "even morons can learn HTML" type tutorial. This is the type of explicit walkthrough beginners want, and theyre going to try to save the site to disk no matter how you try to prevent them. Take it as a compliment, and offer a zipped version of the site for download. At least you'll get a break on the bandwidth.

Busy's picture

He has: 6,151 posts

Joined: May 2001

Thanks, the site was offered as a zip, but since I am updating ALL the content I removed it for now.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.