如何重定向if date.php?date=*未找到或没有';不存在


How to redirect if date.php?date=* not found or doesn't exist

如果找不到".php?date=",有人能告诉我如何重定向到另一个页面吗。我有明确的观点,我认为这就是问题所在,那么如何解决呢?感谢

<!--====================

左块.php==========================-->

<ul class="side-block">
                <li><a href="#">არქივი</a></li>
                <?php 
             $archive = mysqli_query($db,"SELECT DISTINCT left(date,7) as month FROM blog ORDER BY month DESC , id DESC LIMIT 6");
             while($myrow = mysqli_fetch_array($archive)){
                 printf('<li><a href="date.php?date=%s" class="custom">%s</a></li>',$myrow["month"],$myrow["month"]);
                }
?>
            </ul>
<!--
===============================================
date.php
===============================================
-->
<?php 
     include 'bd/blocks/bd.php'; 
     $result = mysqli_query($db,"SELECT keywords,description,author FROM page WHERE page='blog'");
     $myrow = mysqli_fetch_array($result);
if(isset($_GET['date']) && !empty($_GET['date'])){
    $date = $_GET['date'];
}
elseif (!isset($_GET['date']) && empty($_GET['date'])) {
    header("Location: index.php");
    exit;
}
else{
    header("Location: index.php");
    exit;
}
$date= "$date";
$dates=substr($date,0,7);
$result2 = mysqli_query($db,"SELECT date FROM blog WHERE date='$dates' ");
$myrow2=mysqli_fetch_array($result2);
echo mysqli_num_rows($result2);
if(!mysqli_num_rows($result2)){
 header("Location: index.php");
    exit;
}
     $date_title=$date;
     $date_begin =$date;
     $date++;
     $date_end=$date;
     $date_begin=$date_begin.'-00';
     $date_end=$date_end.'-00';
 ?>

在向页面输出任何内容后,不能使用标头进行重定向。使用类似这样的东西来替代javascript替代方案:

else {
    echo("<script>location.href = 'www.myurlhere.com';</script>");
}
<?php 
if(!isset($_GET["date"])){
header("Location: http://newsite");
}
$date=$_GET["date"];
?>

正如macroman所指出的,只有当它位于页面的最顶部,在第一个或echo之前时,这才有效。