PHP header( “Location: /404.php”, true, 404 ) does not work

后端 未结 5 2001
庸人自扰
庸人自扰 2021-01-04 09:04

I\'d like to use the following to redirect pages that are no longer present in the database to the custom 404 page:

ob_start();
....
if ( !$found ):
  header         


        
5条回答
  •  余生分开走
    2021-01-04 09:55

    I think your problem is because of the output buffering you're starting, or because you can't redirect with a 404. The first code example shows the output buffer starting but exiting instead of cleaning the output buffer and stopping output buffering.

    Change the first example to:

    if (!$found) {
      ob_end_clean();
      header('Location: /404.php');
      exit();
    }
    

提交回复
热议问题