.htaccess, PHP and multiple error documents
Hi guys.
I have an interesting question for anyone that may know the answer or even if it's possible.
I'm working with PHP pages and .htaccess error documents. I'm trying to redirect multiple error documents to the same file, error.php, but can't seem to figure out how to distinguish them in the actual file since the ErrorDocument statement doesn't seem to allow queried outputs.
Does anyone know if there is a way to do this without using fake files with redirects?
Cheers.
Re: .htaccess, PHP and multiple error documents
Not sure if this is what you mean, but you can have your errors all redirect to one location...
Code:
ErrorDocument 404 /path/to/error.php
ErrorDocument 403 /path/to/error.php
#etc.
...and then on error.php, you can use any of the variables in $_SERVER to identify details about the error. For example, make this your error.php page:
Code:
<?php
print_r($_SERVER);
?>
And you can see everything you've got to work with.
Re: .htaccess, PHP and multiple error documents
I've tried that. There is nothing in the $_SERVER variable that gives any information about the error. Any there certainty doesn't seem to be anything there that would help distinguish error types apart.
Re: .htaccess, PHP and multiple error documents
You sure?... I've set this up on my domain here (the URL doesn't exist, so what you're seeing is the error page). The error type appears to be in REDIRECT_STATUS: 404.
What type of information are you looking for specifically?...
Re: .htaccess, PHP and multiple error documents
I just checked that and it didn't show anything to do with 404. Hmm. It could be due to the interaction of the other .htaccess documents though. I'll have to do some research on that.
Re: .htaccess, PHP and multiple error documents
Hi,
This is just a thought but could you use the include ('filename here'); statement the include files in the running of the error.php then have code in error.php checking what error was passed and act appropriately?
Re: .htaccess, PHP and multiple error documents
I was going to do something like that but the code was more messy than I like. I had to manually redirect each HTTP error code with the ErrorDocument directive to a file with an error value parameter and render the required page.
Re: .htaccess, PHP and multiple error documents
Keep your existing URLS (they are pointing to the same server right?) and add a reqwrite condition to point them to an alternate PHP script.
Re: .htaccess, PHP and multiple error documents
That would work. It seems not to be needed any more though since I changed the structure of the pages - now the original rewrites work fine :)
Re: .htaccess, PHP and multiple error documents
I shall one day prove to you beyond all reasonable doubt that I am awsome. ;)