RE: [PHP] [php] how to make 404's revert to homepage on a virtual server?
| From: | scott | Date: | Sat, 10 May 2003 12:59:10 +0000 |
| Subject: | RE: [PHP] [php] how to make 404's revert to homepage on a virtual server? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147111@lists.php.net to get a copy of this message | ||
Thanks for the info.
Currently my httpd.conf does not contains an errordocumnet line? I could
add one but what I can't understand is there must be one because I get
the custom raq error page when I try for example.
www.scottincz.com/rubbish.html Where is this page stored on the raq and
what config file points to it?
Best regards
Scott
-----Original Message-----
From: Ernest E Vogelsinger [mailto:ernest@vogelsinger.at]
Sent: 10 May 2003 13:46
To: scott
Cc: php-general@lists.php.net
Subject: Re: [PHP] [php] how to make 404's revert to homepage on a
virtual server?
At 13:24 10.05.2003, scott said:
--------------------[snip]--------------------
>I have a RaQ4 with about 40 virtual sites. I want to create a single
>php script that will make any 404 errors on any of the virtual sites
>revert to the respective sites homepage. Is this possible with one
>script replacing one 404 error page on the raq. I have seen a few ways
>of doing it with htaccess but don't want to have to do that to all the
>sites. Is there a simple way to achieve what I require without having
>to upload and do things to all the sites individually.
--------------------[snip]--------------------
You need to setup some script as a handler for the 404. You can do this
for all virtual sites by putting it in the apache main configuration.
Let's assume you have a script that's located in the virtual web
server's root, named "404.php". In your httpd.conf, you'd add the line
ErrorDocument 404 /404.php
On any 404 error, Apache would try to run this script, located in the
virtual hosts docroot folder. There's only one thing that must be done
on every site - the "404.php" must reside within the virtual server's
document root. This can as well be a symbolic link, so you may want to
put this line in the script that's configuring a new site:
ln -s /<main_host_docroot>/404.php /<virtual_host_docroot>/404.php
Failing to make this handler accessible results in a cascaded 404 error
by Apache.
Ok, what the handler can do:
"404.php" is executed as any other PHP script, where the $_SERVER
superglobal contains the following additional entries:
- REDIRECT_STATUS
The HTTP error number (always 404 in this example, but you could use the
very same handler for different HTTP errors)
- REDIRECT_URL
The path that caused the error (e.g. "/blah/nada.php")
- REDIRECT_REQUEST_METHOD
GET , or POST, or whatever
- REDIRECT_QUERY_STRING
The URL query string, if any (everything after the question mark), in
its original form (parm=value&parm=value) query=something
- REDIRECT_ERROR_NOTES
Human-readable explanation as given by Apache
Your handler script may examine these and proceed as required. The usual
$_SERVER entries apply; e.g. the hostname of the virtual server can
always be found in $_SERVER['SERVER_NAME'].
Hint: you can easily examine all entries by creating a script containing
nothing but
<?php echo phpinfo(); ?>
and register this as Apache error handler.
HTH,
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/