By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

Error 404 enigma

P: n/a
I'm having a problem with finding the URL error value with a custom
error404 (PHP) page - accessed via an .htaccess error redirect.

Let's say I have a link in "test.php" to "wups.php" in a document -
and "wups.php" no longer exists (and I forgot to amend the link in
"test.php").

Is it possible to retrieve the [erroneous] link info?

All I seem to be able to get is the referring page (test.php) and the
actual error page (error.php) that the user gets redirected to.

Adam.
Jun 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Adam wrote:
I'm having a problem with finding the URL error value with a custom
error404 (PHP) page - accessed via an .htaccess error redirect.


try putting print_r($_SERVER) in your errorpage - it may give you a clue.

C.
Jun 16 '06 #2

P: n/a
On Fri, 16 Jun 2006 19:21:39 GMT, Colin McKinnon wrote:
Adam wrote:
I'm having a problem with finding the URL error value with a custom
error404 (PHP) page - accessed via an .htaccess error redirect.


try putting print_r($_SERVER) in your errorpage - it may give you a clue.


Thanks - but no joy :-(

The array spits out the expected variables - but anything related to
URLs (REFERER, SCRIPT_NAME, URI etc.) all point either to the
referring page or the final error page. Nothing contains the failed
URL information.

I'll check the Apache logs to see whether anything gets written there,
but I'm really trying to find a solution that doesn't involve messing
with logs.

Basically, it appears then that if I have a "totally_non_existant.php"
link in a page, a user [rightly] gets the custom error page but
there's no way I can work out what the bad link is - other than that
it's somewhere on that referring page <??>.

Adam.
Jun 18 '06 #3

P: n/a
On Fri, 16 Jun 2006 19:21:39 GMT, Colin McKinnon wrote:
Adam wrote:
I'm having a problem with finding the URL error value with a custom
error404 (PHP) page - accessed via an .htaccess error redirect.


try putting print_r($_SERVER) in your errorpage - it may give you a clue.


To follow up - yes - it *does* get written to Apache's error.log -
with a "script not found or unable to stat" error plus the referring
URL..

There must be a way to trap this in PHP, Shirley?

Adam.
Jun 18 '06 #4

P: n/a
On Sun, 18 Jun 2006 13:11:49 +1200, Adam wrote:
There must be a way to trap this in PHP, Shirley?


To answer my own post (sure sign of madness!):

http://httpd.apache.org/docs/2.1/mod...#errordocument

If your ErrorDocument startswith http:// Apache sends a redirect (302)
to the error document, hence ***losing your original referer***. If
your ErrorDocument points to a relative path, 404 is maintained and so
are your variables.

I was using "http://" in my .htaccess - so $_SERVER['REQUEST_URI'] was
giving me the wrong value.

Using *relative* paths in .htaccess cured the problem - I now get a
full error URL passed to my error.php ... YAY!

Adam.
Jun 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.