In the document root, I put an .htaccess with:
ErrorDocument 404 /error.php
Since this is in a .htaccess file, Apache looks for error.php in the relative path, so I can put different error.php files in different subfolders to get it to execute different error.php:
request /app1/not-exists.txt : yields /app1/error.php
request /app2/not-exists.txt : yields /app2/error.php
request /not-exists/not-exists.txt : yields /error.php
This is desired behavior. However,
request /not-exists/app1/not-exists.txt : yields /app1/error.php
request /app2/app1/not-exists.txt : yields /app1/error.php
This does not seem like expected behavior. I expected:
request /not-exists/app1/not-exists.txt : yields /error.php
request /app2/app1/not-exists.txt : yields /app2/error.php (or maybe /error.php)
or at worst, some generic Apache error handling. Am I misunderstanding what Apache is supposed to do here? The documentation doesn't seem to make this clear.
I think your misunderstanding here is the relative pathing.
.htaccess
files don't have any special behavior that causes paths to be relative; they're essentially the same thing as a<Directory>
block in terms of configuration behavior.ErrorDocument
doesn't have any concept of context; when you enter a path like/error.php
that's always assumed to be relative to the document root, regardless of where it's configured.mod_rewrite
configuration in a<Directory>
block or.htaccess
file uses relative paths, which is probably what you're thinking of for that behavior.A couple options for how you could implement this.. you could have a single
error.php
that pulls in content from the per-app error files depending on the request path?Or you could just use
mod_rewrite
to get the desired error page picking behavior (getting the logic to match what you're looking for is a bit of a complicated mess, though):