首页 > 解决方案 > TYPO3 - 如果页面禁用则重定向

问题描述

我使用TYPO3 6.2

我正在处理一个非常特殊的页面,该页面尚未准备好公开,但我发现 Google 已经找到它并将其编入索引。这是一个真正的问题,因为该页面必须仅适用于 2018 年夏季。

如果我在后端禁用该页面,那么我仍然可以处理它,并且该页面不再可供其他人使用,但 URL 会生成一个404 Not Found.

-> 如何生成一个301 redirect到主页呢?

标签: typo3typo3-6.2.x

解决方案


localconf.php 或 installtool 设置:

#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';

用户函数的内容(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;
}
}
?>

来源:http ://www.typo3forum.net/discussion/34942/301-moved-permanently-statt-404-page-not-found by smartlife 和:http ://blog.marit.ag/2009/03 /20/korrektes-404-错误处理-mit-typo3/


推荐阅读