Paz
04-28-2007, 08:07 AM
Hi,
This is a post with some advice for people who are upgrading their site and will be deleting old pages. Actually, we'd recommend that you don't do this, but sometimes it's unavoidable. When you do have to do make changes, it's vital to be able to 301 redirect as many deleted pages as you can, and to have a proper "404 Not Found" page for the ones you can't.
Not many people realise it but having a custom 404 Not Found page can cause you indexing problems in Google if you're upgrading your site.
The problem is that many custom 404 Not Found pages return a server header "200 OK", which means that the search engines will continue to index the deleted urls with the same content on the 404 Not Found page. This can cause duplicate content problems, particularly if you are removing a few hundred pages or more. Actually, the search engines will figure it out eventually, but it could take months and you can speed things up with the following custom 404 Not Found page.
The following 404.php 301 redirects selected pages that have been deleted, and serves a "404 Not Found" header response for the rest.
<? include $_SERVER['DOCUMENT_ROOT'] . '/globals.local'; ?>
<?
// Permanent redirection: you can have as many as you like, but check that you're not overloading the server.
$page_request_uri = $_SERVER['HTTP_X_REWRITE_URL'];
$arr_page_request_uri = explode('?', $page_request_uri);
$req_path = strtolower($arr_page_request_uri[0]);
$arr_old_pages = array();
$arr_new_pages = array();
$arr_old_pages[] = '/some-old-page01.asp';
$arr_new_pages[] = '/the-new-page01.php';
$arr_old_pages[] = '/some-old-page02.asp';
$arr_new_pages[] = '/the-new-page02.php';
$arr_old_pages[] = '/some-old-page03.asp';
$arr_new_pages[] = '/the-new-page03.php';
// do uri mapping lookups:
$new_path = ''; // default
foreach ($arr_old_pages AS $index=>$this_path){
if ($this_path == $req_path) {
$new_path = $arr_new_pages[$index];
break;
}
}
// handle all exceptions if 404.php has not been specifically requested:
if ($new_path == '' && $req_path != '/404.php') {
$new_path = '/404.php'; // default
}
# do redirection:
if ($new_path > ''){
// Permanent redirection:
header("HTTP/1.1 301 Moved Permanently");
header("Location: {$new_path}");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>404 Not Found</title>
<meta name="Description" content="The page you are looking for has been removed." />
</head>
<body>
<table width="760" height="146" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="250"> </td>
<td width="510" valign="top">
<h1 style="font-size:24px; margin-top: 60px; ">404 Error Page:</h1>
<p>We're sorry, the page you requested cannot be found, please visit our home page, or use our sitemap to find the page you were looking for.</p>
</td>
</tr>
</table>
</body>
</html>
Thanks to our php guru Bruce Perkins (http://www.brucepeterkin.co.uk) for this one!
Cheers,
Paz.
This is a post with some advice for people who are upgrading their site and will be deleting old pages. Actually, we'd recommend that you don't do this, but sometimes it's unavoidable. When you do have to do make changes, it's vital to be able to 301 redirect as many deleted pages as you can, and to have a proper "404 Not Found" page for the ones you can't.
Not many people realise it but having a custom 404 Not Found page can cause you indexing problems in Google if you're upgrading your site.
The problem is that many custom 404 Not Found pages return a server header "200 OK", which means that the search engines will continue to index the deleted urls with the same content on the 404 Not Found page. This can cause duplicate content problems, particularly if you are removing a few hundred pages or more. Actually, the search engines will figure it out eventually, but it could take months and you can speed things up with the following custom 404 Not Found page.
The following 404.php 301 redirects selected pages that have been deleted, and serves a "404 Not Found" header response for the rest.
<? include $_SERVER['DOCUMENT_ROOT'] . '/globals.local'; ?>
<?
// Permanent redirection: you can have as many as you like, but check that you're not overloading the server.
$page_request_uri = $_SERVER['HTTP_X_REWRITE_URL'];
$arr_page_request_uri = explode('?', $page_request_uri);
$req_path = strtolower($arr_page_request_uri[0]);
$arr_old_pages = array();
$arr_new_pages = array();
$arr_old_pages[] = '/some-old-page01.asp';
$arr_new_pages[] = '/the-new-page01.php';
$arr_old_pages[] = '/some-old-page02.asp';
$arr_new_pages[] = '/the-new-page02.php';
$arr_old_pages[] = '/some-old-page03.asp';
$arr_new_pages[] = '/the-new-page03.php';
// do uri mapping lookups:
$new_path = ''; // default
foreach ($arr_old_pages AS $index=>$this_path){
if ($this_path == $req_path) {
$new_path = $arr_new_pages[$index];
break;
}
}
// handle all exceptions if 404.php has not been specifically requested:
if ($new_path == '' && $req_path != '/404.php') {
$new_path = '/404.php'; // default
}
# do redirection:
if ($new_path > ''){
// Permanent redirection:
header("HTTP/1.1 301 Moved Permanently");
header("Location: {$new_path}");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>404 Not Found</title>
<meta name="Description" content="The page you are looking for has been removed." />
</head>
<body>
<table width="760" height="146" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="250"> </td>
<td width="510" valign="top">
<h1 style="font-size:24px; margin-top: 60px; ">404 Error Page:</h1>
<p>We're sorry, the page you requested cannot be found, please visit our home page, or use our sitemap to find the page you were looking for.</p>
</td>
</tr>
</table>
</body>
</html>
Thanks to our php guru Bruce Perkins (http://www.brucepeterkin.co.uk) for this one!
Cheers,
Paz.