Arth Arth - 3 years ago 177
Apache Configuration Question

Apache ErrorDocument 404 in subdirectory without .htaccess

I'm doing some performance enhancements and came across the recommendation that

files can (and should) be rolled up into the

From the Apache
How To

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server.

As part of my initial exploration I'm just including the root
file in my virtual host configuration, with a view to neatening it up later.

Mostly it appears to work and in it is this directive:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpg|jpeg|png|gif|ico|swf|bmp)$ - [L,R=404,NC]

Unfortunately, we also have an
file in an
directory with the following directive:

ErrorDocument 404 /images/notfound.gif

Which replaces any 404'd images with a 'Not Found' image.

Is this behavior possible to recreate within the root
? Eventually this would be included in the virtual host configuration.

I tried using the following, but wasn't surprised when it threw a 500 error:

ErrorDocument images/404 /images/notfound.gif

Answer Source

You can do this in your Virtual host .conf or the global httpd.conf (aka apache2.conf) file. The important point here is that you only do it for your /images/ directory otherwise you will get this notfound.gif in any 404 error.

e.g. for the httpd.conf or Virtualhost

<Location /images>
    ErrorDocument 404 /images/notfound.gif

You can also use the Directory Directive

<Directory /absolute/path/to/images>
    ErrorDocument 404 /images/notfound.gif

If you have only one Website on your Server that you could put it in your httpd.conf but the better solution is the Virtualhost configuration.

ErrorDocument images/404 /images/notfound.gif is the wrong syntax see:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download