菜单

403,404,500多语言errorPage

2010年08月5日 - typo3

Background:

When people manage there website, and in this case deleting page then we need to make sure that all search engines also need to know that a page doesn’t exist anylonger.

By default (correct me if I am wrong) TYPO3 3.8.x will find the nearest page but will not send out a appropriate 404 header

Shown using live HTTP headers.
=>  GET /productos-planos/dgdfg.html HTTP/1.1
<=  HTTP/1.x 200 OK

Good news for RCx testers and users for the upcomming 4.0 release, In TYPO3 version 4.0 this particular problem is solved.

Shown using live HTTP headers.
=> GET /nopage.html HTTP/1.1
<= HTTP/1.x 404 Not Found

The solution:

1. 404页面

The solution for TYPO3 users on version 3.8.1

I found it that for some reason it is really not possible to make TYPO3 version 3.8.x send a appropriate header. TYPO3 does provide ‘some’ answers but looking at the code it simply doesn’t send a real header(“HTTP/1.0 404 Not Found”); Am I wrong here????

My solutions consist of two steps, first we need to create under typo3conf/localconf.php the following entry:
$TYPO3_CONF_VARS[“FE”][“pageNotFound_handling”] = ‘USER_FUNCTION:fileadmin/scripts/pagenotfound.php:user_pagenotfound->pagenotfound’;

By doing this we tell TYPO3 that we have our own code for 404 handling.
Under fileadmin/scripts/ we create the following file pagenotfound.php.

<?php
define(‘REDIRECTPAGE’, ‘/404.html’);
class user_pagenotfound {
function pagenotfound($param, $conf) {
$server_name = $_SERVER[‘SERVER_NAME’];
$reg = array();
preg_match(“/^\/([a-zA-Z]*)\/(.*)/”, t3lib_div::getIndpEnv(‘REQUEST_URI’), $reg);
$lang = $reg[1];
switch($lang){
case ‘de’:
$server_name .= ‘/de’;
break;
case ‘en’:
$server_name .= ‘/en’;
break;
}
header(“HTTP/1.0 404 Not Found”);
print ‘<!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” xml:lang=”en” lang=”en”>
<head>
<title>Page not Found!</title>
<SCRIPT LANGUAGE=”JavaScript”>
<!–
function doRedirect() {
window.location=”http://’.$server_name.REDIRECTPAGE.'”;
}
doRedirect();
// –>
</script>
</head>
<body style=”font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;text-align:center;”;>
<div style=”font-size:20px;text-align:center”>The page you have requested cannot be found</div>
<div>If you are not automaticly redirected in 3 seconds please click here: <br />
<br /><a href=’.$server_name.’>’.$server_name.'</a></div>
</body>
</html>’;
exit;
}
}

?>

How does it work:

When TYPO3 can’t find a page it will call the function pagenotfound in the class user_pagenotfound. Then my PHP code will send a appropriate header and shows a message. Using java I set a timeout and after 1000 ms java fires and calls doRedirect.
When java was not available then a user can always click the provided link.

exec_SELECTcountRows('1', 'pages', 'deleted=0 and hidden=0 and uid='.($GLOBALS['TSFE']->id?$GLOBALS['TSFE']->id:0))==0){
			header("HTTP/1.0 404 Not Found");
			header("Location:http://".$server_name.REDIRECTPAGE);
		}else{
			header("HTTP/1.0 403 Not Found");
			header("Location:http://".$server_name.REDIRECTPAGE_403);
		}
		exit;
	}
}

?>

2. 403,500页面

等待更新

发表评论

电子邮件地址不会被公开。 必填项已用*标注