Reputation: 568
I use TYPO3 6.2.
I'm working on a very special page which is not ready for public but I discovered that Google already found it and indexed it. This a a real problem because the page has to be available only for the 2018 summer.
If I disable the page in the back-end then I can still work on it and the page is no longer available for other people, but the URL generates a 404 Not Found
.
-> How to generate a 301 redirect
to the homepage instead ?
Upvotes: 0
Views: 355
Reputation: 484
localconf.php or installtool settings:
#have to be 1
$TYPO3_CONF_VARS['SYS']['curlUse'] = 1;
#have to be empty
$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['init']['postVarSet_failureMode'] = '';
#logical part
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = '/404.html';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.1 301 Moved Permanently';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'USER_FUNCTION:fileadmin/scripts/pagenotfound.php:user_pagenotfound->pagenotfound';
content of user function (fileadmin/scripts/pagenotfound.php)
<?php
define('REDIRECTPAGE', '/');
class user_pagenotfound {
function pagenotfound($param, $conf) {
$server_name = $_SERVER;
header("HTTP/1.0 301 Moved Permanently");
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>301 Moved Permanently</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;
}
}
?>
Source from here: http://www.typo3forum.net/discussion/34942/301-moved-permanently-statt-404-page-not-found by smartlife And: http://blog.marit.ag/2009/03/20/korrektes-404-error-handling-mit-typo3/
Upvotes: 1