正确的404重定向PHP?
|
我必须使用自定义404页面进行url重定向(.htaccess不是一个选项)。我正在考虑使用以下代码。我正在尝试通过向URL添加标记来考虑有效的重定向以及未找到页面的真实情况。你怎么看?
<?php
// check GET for the flag - if set we\'ve been here before so do not redirect
if (!isset($_GET[\'rd\'])){
// send a 200 status message
header($_SERVER[\'SERVER_PROTOCOL\'] . \' 200 Ok\');
// redirect
$url = \'new-url/based-on/some-logic.php\' . \'?rd=1\';
header(\'Location: \' . $url);
exit;
}
// no redirection - display the \'not found\' page...
?>
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>404:</h1>
<h3>Sorry, the page you have requested has not been found.</h3>
</body>
</html>
编辑-不能选择.htaccess的原因是因为我在IIS6上没有apache运行。
没有找到相关结果
已邀请:
3 个回复
扭湘阀柿蹄
并删除200个代码:
骨酚柯
蓟类
或类似的字符。 紧接着,如果未找到模块,则将使用错误页面模板。我将其命名为“ 4”,因此您还需要创建该文件。 最后,即使找不到错误模板,也将返回标准的404错误消息。