Forum Moderators: phranque

Message Too Old, No Replies

Do not log 404

...in a specific dir

         

kullervo

2:47 pm on Jan 7, 2006 (gmt 0)

10+ Year Member



People hot-links alot to images on one of my websites. That is ok, but what disturbes me is when I remove a file. Then I gets alot of 404-errors in my error.log. How can I tell Apache not to log those errors for a specific directory? Do I have to pipe the errorlog to grep?

jdMorgan

4:00 pm on Jan 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Several ways to fix this:

1) If you have access to httpd.conf, use the CustomLog [httpd.apache.org] and SetEnvIf directives to log those requests to /dev/null
2) Use mod_rewrite to rewrite those requests to a special 'hotlinker' image file (put your logo and URL on it)

Jim

kullervo

4:40 pm on Jan 7, 2006 (gmt 0)

10+ Year Member



Yes, I have access to http.conf. I've already read the chapter about Conditional Logs and SetEnvIf but I can't find a way to trig on response status code.

mod_rewrite seems to trig with the following condition:
RewriteCond /your/docroot/%{REQUEST_FILENAME}!-f
But the Apache manual warn about this beeing slow and I've got alot of requests. I would prefer conditional loging.

jdMorgan

6:25 am on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you remove a file, you can add it to a list of SetEnvIfs:

SetEnvIf Request-URI ^removed_file_1.gif removed
SetEnvIf Request-URI ^removed_file_2.jpg removed
#
CustomLog /dev/null common env=removed

Or, you can use mod_rewrite and reduce the number of times that the filesystem has to be checked by using a specific directory (or Location) container and specific filetypes:

<DirectoryMatch ^/path_to_image_directory$>
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(gif¦jpe?g)$ - [E=removed:1,L]
</DirectoryMatch>
#
CustomLog /dev/null common env=removed

The second method requires that mod_rewrite runs before mod_customlog. Note that as described in the documenation, RewriteConds will not be evaluated unless the RewriteRule pattern matches. Therefore, the filesystem check is not executed unless the request is for a gif, jpg, or jpeg file (in this example).

Also, I can't remember if the var in the RewriteRule needs to be set to '1', or 'True', or just set to any non-blank value.

I haven't tested this code. You may need to tweak it a bit.

Change all broken pipe "¦" characters to solid pipes before trying to use this code; Posting on this board modifies them.

Jim

kullervo

12:02 pm on Jan 8, 2006 (gmt 0)

10+ Year Member



There is millions of images so I can't use "SetEnvIf Request-URI ^removed_file_1.gif removed". The rewrite method seems to work fine. Thank you!

What do you think of using a custom made ErrorDocument with error logging turned off? It should be faster then a rewrite rule.

jdMorgan

4:53 pm on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> a custom made ErrorDocument with error logging turned off?

I'm not sure how that would work... Give it a try and let us know!

Three options are better than two... :)

Jim