404 redirect, and the calling URL

tinklerb

204.***.***.***
1,776 days ago

404 redirect, and the calling URL

Folks,

I have a "default" page that anyone requesting a page on the site that does not exist is redirected to. (a default 404 page not found page)

I would like to show them the URL they requested on the 404 page, but the site's redirect to the default 404 page seems to be blanking out my ability to use the $_SERVER['HTTP_REFERER'] global in PHP. It comes up blank every time.

Is there some other way to trap the page they have typed in the URL as a displayable variable? I have seen sites where it comes up and says "The page you requested (bad url string goes here) does not exist, please try again" and this is what I would like to have happen.

I'm sure I've missed something simple. It CAN'T be this hard...

Well, I hope not.

sandykadam

202.***.***.***
1,776 days ago
Hi,

You can redirect user to your customized page using .htaccess. In .htaccess you just need to give path of your customized file name. Following is syntax.

ErrorDocument 404 yourcustomizedfilename.php

So now whenever any user opens an non-existing file he will be redirect to above page. If you want to track which page he entered then you can put some code of referrer in that.

Bill

80.***.***.***
1,771 days ago
Welcome to the forum, Tinkler.

Try $_SERVER['REQUEST_URI'].

Neotropic

70.***.***.***
935 days ago
What I always use:
ErrorDocument 401 errors.php?code=401
ErrorDocument 500 errors.php?code=500
ErrorDocument 403 errors.php?code=403
ErrorDocument 400 errors.php?code=400
ErrorDocument 404 errors.php?code=404

If nothing happens then add full URL:
ErrorDocument 401 http://www.mysite.com/errors.php?code=401
ErrorDocument 500 http://www.mysite.com/errors.php?code=500
ErrorDocument 403 http://www.mysite.com/errors.php?code=403
ErrorDocument 400 http://www.mysite.com/errors.php?code=400
ErrorDocument 404 http://www.mysite.com/errors.php?code=404

Code:


switch($_REQUEST['code']){
case '400':
$title = 'Bad Request';
$error = 'The server was unable to send your request.';
break;

case '401':
$title = 'Unauthorized';
$error = 'You are not authroized to access this page.';
break;

case '403':
$title = 'Forbidden';
$error = 'You are not authroized to access this page.';
break;

case '404':
$title = 'Page Not Found';
$error = $_SERVER['REQUEST_URI'] . ' was not found on our server. Please check the URL and make sure it was entered correctly.';
break;

case '500':
$title = 'Server Error';
$error = 'The server encountered an error. If the problem persists please contact the website administrator.';
break;
}


Display HTML here