Apache: Infinite redirect for custom 404 page

I needed a custom 404 page for a specific subdirectory in my document root.

I tried several combinations but could not get the page to serve up without an infinite redirect.

Related tags: Apache

Credit: trial and error :)

Turns out that order is important.

I had to put the custom 404 directive after the default directive:

ErrorDocument 404 "Sorry, the web page your are trying to view does not exist."
ErrorDocument 403 "Permission Denied."

<Directory /doc_root/subdir/>
ErrorDocument 404 /subdir/404.php

The infinite redirect happens when the ErrorDocument cannot be found. The custom document won't be loaded unless it is declared after the general one.

Rating: 1

Propose a different solution...