The problem is that this is a program that I want to use in lots of places, and I don't want to modify the structure of the whole site each time. I really want to get it to work in an isolated folder, without affecting what's outside.
Why not have one ErrorDocument handle all the errors in all the folders? Might be much cleaner that way. You could then handle the individual case using $_SERVER["REQUEST_URI"] which should contain the original request if I remember correctly.