Skip to content

Instantly share code, notes, and snippets.



Created Oct 30, 2014
What would you like to do?
An improved 404 page
* I see lots of cute 404 pages with funny messages.
* Most 404 pages don't tell you what link you used to get to the 404,
* and they don't really give you options on how to get to where you want to go
* other than "Click here to return to our front page."
* That approach is as bad as
* Sadly, this page doesn't do anything fancy like list other articles.
* Using DuckDuckGo because it's better than Google.
header("HTTP/1.0 404 Not Found");
$suggest = false;
if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != "") {
$suggest = true;
$suggestion = $_SERVER['REQUEST_URI']; // Gives people the URL they visited so they know what to search for.
} else {
$suggestion = "";
<!DOCTYPE html>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<style type="text/css">
/* */
html, body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
font-size: 10px;
display: table;
div {
text-align: center;
display: table-cell;
vertical-align: middle;
#ddg {
p {
font-size: 2em;
.disclaimer {
font-size: 1.2em;
.disclaimer a, .disclaimer a:hover, .disclaimer a:active {
color: inherit;
<title>Not found</title>
<?php if ($suggest === true) { ?>
<p>We can't find <?php echo($suggestion); ?> here.</p>
<p>What were you looking for?</p>
<?php } else { ?>
<p>What were you looking for? </p>
<?php } ?>
<iframe id="ddg" src="<?php
echo $_SERVER['SERVER_NAME']; // the part of the URL
?>&prefill=Search this site&focus=yes" frameborder="0"></iframe>
<p class="disclaimer">This search box uses <a href="">DuckDuckGo</a>, a privacy-positive search engine.</p>
<p><a class="button" href="http://<?php echo $_SERVER['SERVER_NAME']?>">To the homepage!</a></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment