WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Search Engine Friendly, User friendly 404 error page
Categories : PHP, URLs, Filesystem Click here to Update Your Picture
Vinod Mohan
Date : Dec 29th 2008
Grade : 1 of 5 (graded 3 times)
Viewed : 4271
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Vinod Mohan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

The default 404 error page shown by Apache is not at all helpful for a user. Fortunately, apache allows us to use our own custom 404 error pages. Some people use this feature to redirect 404 errors to their site's homepage. But this is also not useful for a user or a search engine. Some provide custom error pages that are useful for their users, but does not provide the required 404 header which can make the search engines penalize you for duplicate content. Here is a 404 custom 404 error page that will satisfy both your users and search engines. It also includes Google's custom 404 search box code.

Save the following as 404.php in your document root

<?php
// Change this to your site url
$homeUrl = 'http://www.weberdev.com/';

// Add the 404 header to not confuse search engines
header("HTTP/1.0 404 Not Found");
$arPath = explode('/', $_SERVER['REQUEST_URI']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 Error - Page not found</title>
<meta http-equiv="refresh" content="10;url=<?php echo $homeUrl;?>" />
<style type="text/css">
*{margin:0px;padding:0px;}
body{background-color:#F9F9F9;color:#111;font: normal 95%/130% "Trebuchet MS", Verdana, Arial, sans-serif;margin:0px;padding:20px 0px;}
a {color:#6699CC;text-decoration:none;border-bottom: 1px solid #EEE;}
h1{color:#333;font:normal 1.7em Georgia, "Times New Roman", Times, serif;margin:0px;padding:0px;}
h2,h3{color: #6699cc;font: normal 1.25em Georgia, "Times New Roman", Times, serif;margin: 20px 0px;padding: 0px;}
ul{margin:10px 20px;}
li{list-style:disc;}
#wrapper{background-color:#FFFFFF;border:1px solid #DDDDDD;margin:auto;width:40em;}
#header {background:#D5D5D5;border-bottom:1px solid #DDD;color:#888;font-size:85%;margin:0px;padding:3px 10px;}
#body{padding:10px;}
#goog-wm { }
#goog-wm h3.closest-match { }
#goog-wm h3.closest-match a { }
#goog-wm h3.other-things { }
#goog-wm ul li { }
#goog-wm li.search-goog { display: block; }

.comment{color:#999;}
</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<a style="text-transform:uppercase;" href="<?php echo $homeUrl;?>"><?php echo str_replace(array('http://', 'www.', '/'), '', $homeUrl);?></a> → Page not found</div>
<div id="body">
<h1>[404] Page not found</h1>
<p> </p>
<p>Sorry, the file <code class="comment"><?php echo $_SERVER['REQUEST_URI'];?></code> was not found on this server.</p>
<p>Please ensure that you have entered the url correctly. If you did so, then probably the file was removed from the server.</p>
<p>Please choose one of the actions from below, or you will be redirected to our homepage in 10 seconds.</p>
<ul>
<li><a href="<?php echo $homeUrl;?>">Click here to go to the homepage.</a></li>
<li><a href="javascript:history.back();">Click here to go back.</a></li>
<li><a href="<?php echo $homeUrl;?>/contact.php">Click here to contact us.</a></li>
</ul>
<div id="leftContent">
<script type="text/javascript">
  var GOOG_FIXURL_LANG = 'en';
  var GOOG_FIXURL_SITE = '<?php echo $homeUrl;?>';
</script>
<script type="text/javascript"
    src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
</div>
</div>
</div>
</body>
</html>


Create a file .htaccess in your document root (if one does not already exist). Add the following line to the end of the file

ErrorDocument 404 /404.php


That is it. Now you have a search engine friendly and at the same time user friendly 404 error page.



php jump urls...the best way
Categories : PHP, URLs, Filesystem
a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts
Categories : PHP, URLs, Directories, Filesystem
Unix Disk Information with graphs
Categories : PHP, Shell Scripting, Filesystem
directory, opendir, listfiles, files in a directory, get directory
Categories : PHP, Filesystem
Show Source with Line Numbers
Categories : PHP, Regexps, Filesystem
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
How to find the name of the current file?
Categories : PHP, Filesystem, Strings
Opening and formatting text files into HTML on the fly- or HTML from templates.
Categories : PHP, HTML and PHP, Filesystem
Image Browser
Categories : Filesystem, GD image library, Content Management, PHP
Differences between two files
Categories : PHP, Filesystem, Tip
phpHoo2 (Xhoo using php3/MySQL) is a Yahoo-like link directory. Much like the Open Directory Project (dmoz.org).
Categories : PHP, Complete Programs, Directories, MySQL, URLs
Fetching product details from the commission junction website using php
Categories : PHP, FTP, Filesystem, Compression
Single-file PHP news system with automatic folder structure creation
Categories : PHP, Filesystem, Arrays
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database.
Categories : PHP, Filesystem, FTP, Date Time, Databases