DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Richard has posted 22 posts at DZone. View Full User Profile

.htaccess Error404.php

  • submit to reddit
        // This goes in .htaccess in the web root.

# error docs
ErrorDocument 404 /error404.php

// Use existing site template to start 404 page then add this code in your main content div.

<h1>Page not found</h1>
/* Error 404 code for ***** website */

$webmaster = "";
$host     = getenv("REMOTE_HOST");
$referrer = getenv("HTTP_REFERER"); 
$path     = getenv("REQUEST_URI"); 

// time in this format: 13/Nov/2000:10:50:38
$time = strftime("%d/%b/%Y:%T");

if ($referrer == "") {
  $referrer = "";
} else {
  $referrer = "<p>You came to this page from $referrer, this could be a broken link so please <a href=\"mailto:$webmaster?subject=Error 404 on $path from $referrer\">email the webmaster</a> to inform us of this.</p>";

<h2>Sorry, we couldn't find the page <?php echo $path ?> on this website</h2>
<?php echo $referrer; ?>
<p>Please use the navigation links to help locate what you're looking for.</p>