Page 1 of 1

404, grab the url missing?

Posted: Tue Aug 19, 2003 2:20 pm
by Dream
I've made a 404 Not found page, (404.php)

I. trying to get the url they request to show up on the page. like The resource you have requested (http://w2r.net/AnErrorUrl.html) does not exist.

But its just grabbing the url to the 404.php file, and not the url that was missing. e.g. The resource you have requested (http://w2r.net/error/404.php) does not exist.

Code: Select all

The resource you have requested (<strong>http://w2r.net<?= $_SERVER&#1111;'REQUEST_URI'] ?></strong>) does not exist.
is my code wrong maybe? I'm kind empty of ideas on how to make it work.. any ideas?


Here is a complete view of the source "404.php"

Code: Select all

<? 

	# Some variables for the log
		$now = gmdate('Y-m-d H:i:s');
		$ip_address = gethostbyaddr($_SERVER&#1111;'REMOTE_ADDR']);
		$requested_page = str_replace('|', '&#124;', $_SERVER&#1111;'REQUEST_URI']);
		$referer = $_SERVER&#1111;'HTTP_REFERER'];

	# let's write this information to a local file
		$fp = fopen("/hsphere/local/home/w2rnet/w2r.net/error/404log.txt", "a+");
		fputs($fp, $now .' |'. $ip_address .' |'. $referer .' |'. $requested_page ."\n");
		fclose($fp);
?>	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>404 - File not found.</TITLE>
	<link rel="stylesheet" href="../demo/style.css" type="text/css" />

</head>

<body>

	<div align="center">
	<p><br>	</p>
	<table width="80%" border="0" cellspacing="4" cellpadding="4">
	<tr>
	<td colspan="2" valign="bottom">

	<div class="title">
	<center>404.  File not found.</center>
	</div>
              </td>
	</tr>
	<tr>
	<td colspan="2">
The resource you have requested (<strong>http://w2r.net<?= $_SERVER&#1111;'REQUEST_URI'] ?></strong>) does not exist.  It has never existed.  Any suggestion to the contrary is nothing but the scandalous lie of a greasy weavil-eating snot-monkey.<br>
<br>
There is no use in crying about it.  I'm as upset about the whole thing as you are.  
There's nothing to be gained by pointing fingers and giving voice to wild accusations about who moved what directory where, or who renamed this file that.  
Suffice it to say that whatever it is you're looking for won't be found by way of here.<br>
<br>
There is always hope: you may simply have mistyped the address.  Feel free to take another stab at it.  You'll probably end up here again though, so don't say I didn't warn you.<br>
<br>
You can explore the <a href="http://www.w2r.net/">site map</a>, or you can just return <a href="javascript:history.go(-1)">whence you came</a>.
	</td>
	</tr>
	</table>
	</div>


</body>
</html>

Posted: Tue Aug 19, 2003 3:02 pm
by macewan
ErrorDocument 404 404.php



place that in your .htaccess

Posted: Tue Aug 19, 2003 3:55 pm
by Dream
I already have the scripts works. its just that its fetching the wrong url.

I think I didnt explain myself good enough.. I tend to do that sometimes :P

you can test it out at my domain: http://www.w2r.net

follow this url: http://www.w2r.net/AnErrorUrl.htm

This files doesnt exsist, so my .htaccess redirects this to 404.php. This is working just fine.
My problem is the php scripts.
I want it to generate the bad url the person requested. Like

print:
The resource you have requested (http://w2r.net/AnErrorUrl.html) does not exist.

But instead, it becomes like this:
The resource you have requested (http://w2r.net/error/404.php) does not exist.


Here is my .htaccess code if you want to check it for errors:

Code: Select all

order allow,deny

allow from all

ErrorDocument 401 /error/401.php
ErrorDocument 403 http://www.w2r.net/error/403.php
ErrorDocument 404 http://www.w2r.net/error/404.php
ErrorDocument 500 http://www.w2r.net/error/500.php
But I dont think the error is my .htaccess.

Posted: Fri Mar 19, 2004 5:30 pm
by RichardCreek
If you're still using this:
order allow,deny

allow from all

ErrorDocument 401 /error/401.php
ErrorDocument 403 http://www.w2r.net/error/403.php
ErrorDocument 404 http://www.w2r.net/error/404.php
ErrorDocument 500 http://www.w2r.net/error/500.php

Try changing the 404 line to

ErrorDocument 404 /404.php
the absolute URL is probably what's making $REQUEST_URI return the wrong result.

Rich :?