Forum Moderators: phranque

Message Too Old, No Replies

Variable in .htaccess ErrorDocument

Is it possible?

         

inuwolf

2:44 am on Feb 22, 2006 (gmt 0)

10+ Year Member



Instead of writing
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html

Could I write

ErrorDocument (variable) /errors/error.php?(variable)

Are variables even possible in .htaccess? If so, this would make custom error documents a lot easier.

jdMorgan

3:38 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, you can't put variables in there. However, you could point all error handlers to one script, and have the script sort out what to do based on existing server and HTTP_REQUEST variables.

You *can* append a fixed query string to the ErrorDocument URL-path, if that helps. And you can also rewrite ErrorDocument URL-path requests using mod_rewrite, which also might help.

It really depends on what overall goal you're trying to get to, and why.

Based on the example you posted, I want to add that I think it is a very dangerous thing to point 500-Server Error handling to a script. If you get a 500-Server Error, that's a potentially-very-serious problem. Handling it should invoke the absolute bare minimum of dependencies.

I recommend handling 500-Server Errors with completely-static html pages with no images or includes of any kind. Otherwise, if you have say, an error in one of your common content-handling or authorization scripts, you face the possibility of that one 'small' error causing a catastrophic cascade of events that brings your entire server down. In other words, if you get a 500-Server Error while trying to process a 500-Server Error, and that in turn generates another and another and another... because a common script has an obscure bug in it or an image has been moved or misnamed, that's very bad news.

Jim

inuwolf

3:59 am on Feb 22, 2006 (gmt 0)

10+ Year Member



It really depends on what overall goal you're trying to get to, and why.

I'm trying to have a single error page encompass every possible error that simply prints the error code and a brief description while maintaining the CSS style of the site. Since I'm familiar with PHP I'd like to use something like PHP and something like HTTP_REQUEST variables to determine the error. I hadn't thought about the catastrophic implications of an Error 500 loop, so I'd avoid customizing the 500 Error if possible.

However, you could point all error handlers to one script, and have the script sort out what to do based on existing server and HTTP_REQUEST variables. You *can* append a fixed query string to the ErrorDocument URL-path, if that helps. And you can also rewrite ErrorDocument URL-path requests using mod_rewrite, which also might help.

How would one go about doing this, or something like I described above? Is there any way to redirect multiple errors to one variable page?

jdMorgan

4:46 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use php to get the server variables, HTTP request variables, and query string parameters, and base its action upon them.

Since this is becoming a PHP question, I'd suggest asking about it in our PHP forum, with the basic premise of an ErrorDocument definition like:


ErrorDocument 400 /error.php?error_code=400
ErrorDocument 401 /error.php?error_code=401
ErrorDocument 403 /error.php?error_code=403
ErrorDocument 404 /error.php?error_code=404
ErrorDocument 410 /error.php?error_code=410

Jim

inuwolf

5:00 am on Feb 22, 2006 (gmt 0)

10+ Year Member



thanks a lot. can't believe I didn't think of that.