Jamit Software Forum
Welcome, Guest. Please login or register.
September 25, 2022, 11:08:21 am

Login with username, password and session length
Search:     Advanced search
May 27th, 2009 - Jamit Software Launches the forum today!
3,080 Posts in 791 Topics by 1,936,655 Members
Latest Member: Tornalunk
* Home Help Search Login Register
+  Jamit Software Forum
|-+  Jamit Job Board Customers
| |-+  User-to-User Support
| | |-+  404 error trick
« previous next »
Pages: [1] Print
Author Topic: 404 error trick  (Read 5957 times)
« on: January 06, 2011, 11:03:15 pm »


Been searching for 404 errors and how to redirect them and i found a good trick for and very usefull so i think its a good idea to share with JJB you never know who's gonna need it.
It redirects the user to the page he used to be before and its sending you an email with a description of error which user encounter.
Just create an .txt file named 404.txt ....copy and paste the below text into....save...rename the 404.txt to 404.php ....upload it to your public folder for your website and should work. It worked well for me and is doing a very good job.
P.S. you need to add ErrorDocument 404 /404.php in your .htaccess file in order to work.
I've added the file as attachment if you're lazy enough. Grin Edit it as you like.
I hope I've been friendly enough with the description. 

$sendMail = "yes";   // must be set to "yes" for the email to be sent
$emailAddress = "[email protected]";  // set to your email address
putenv('-2GMT');  // set to your time zone
// change nothing below this line
$domain = $_SERVER['HTTP_HOST'];
$page = $_SERVER['REQUEST_URI'];
if ($sendMail == "yes") {
  $errortime = (date(" F d h:ia"));
  $browser = $_SERVER['HTTP_USER_AGENT'];
  $referer = $_SERVER['HTTP_REFERER'];
  $message = "";
  $message .= "Time of the error: $errortime\n\n";
  $message .= "browser: $browser\n\n";
  $message .= "Page Requested: $domain$page\n\n";
  $message .= "Referer: $referer\n\n";
  $message .= "IP Address: $IP\n\n";
  $name = gethostbyaddr($IP);
  $message .= "Hostname: $name\n\n";
  mail($emailAddress, "404 Error" , $message, "From: Website <>");
header("HTTP/1.0 404 Not Found");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="refresh" content="1;url=http://www.yoursite.com/">
<title>404 - where oh where?</title>
<style type="text/css">
A:link {text-decoration: none; font-weight:bold; color: blue}
A:hover {color: red}
<div style="width: 400px; position: absolute; top: 45px; left: 50%; margin-left: -200px;">
<span style="color: teal; font-size: 32px;">file not found</span>
<br /><br /><br />
<span style="color: black; font-size: 18px;">
<br /><br />
it appears you were looking for
<br />
<span style="color: teal; font-size: 18px;"><?=$domain?><?=$page?></span>   
<br /><br /> 
however, since you are here, it is clear you did not get what you wanted.
<br /><br /> 
the problem has been reported so any broken links can be found and repaired.
<br /><br /> 
you can click <a href="javascript:history.go(-1)">here</a> to go back to your previous page.
Hero Member
Posts: 150

« Reply #1 on: January 07, 2011, 04:11:57 am »

That looks pretty cool. I've been using "ErrorDocument 404 http://www.mycoolsite.com" to redirect back to the home page.

I will try this out and see what it looks like.
Hero Member
Posts: 150

« Reply #2 on: January 07, 2011, 04:13:41 am »

I would also add an option to go to the home page in addition to the link to go back to the previous page.
Global Moderator
Hero Member
Posts: 255

« Reply #3 on: January 08, 2011, 07:20:32 am »

Thanks, I have been using similar script on one my sub pages.
It works out really nice, and sends out an email about 404 so that we can fix it and displays a nice message.
Sr. Member
Posts: 51

« Reply #4 on: January 08, 2011, 08:27:51 am »

In the attached file, dont we need to replace "http://www.yoursite.com/" in line 28 with the JJB site's own domain?
« Reply #5 on: January 08, 2011, 09:58:00 am »

Yes jaffri correct
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.045 seconds with 17 queries.