typo3 - TYPO3 - 如果页面禁用则重定向
问题描述
我使用TYPO3 6.2。
我正在处理一个非常特殊的页面,该页面尚未准备好公开,但我发现 Google 已经找到它并将其编入索引。这是一个真正的问题,因为该页面必须仅适用于 2018 年夏季。
如果我在后端禁用该页面,那么我仍然可以处理它,并且该页面不再可供其他人使用,但 URL 会生成一个404 Not Found
.
-> 如何生成一个301 redirect
到主页呢?
解决方案
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/
推荐阅读
- javascript - Can you refer to constructor function's property inside constructor's arguments?
- python - 如何在管理面板中更改日期时间格式?
- html - 试图居中元素并强制滚动
- python - 如何在 python 中使用 id 的 kivy?
- python-3.x - 在 python 的函数中使用 exec() 时出错的原因
- python - 连接 2 个数据帧(更新)按总和聚合
- javascript - 如何在反应原生导航器中执行异步代码?
- macos - APFS 是否真的支持命名分叉或仅支持资源分叉和扩展属性?
- web - Meteor 和 Godaddy 的 URL 重定向如何工作
- scala - 具有较低类型边界的 Scala 抽象类类型。我无法理解