header('HTTP/1.0 404 Not Found'); not doing anything

后端 未结 7 1916
孤街浪徒
孤街浪徒 2020-12-09 07:30

I have a 404.php file in my site\'s main directory and I was using header(\'Location: 404.php\'); for a while until someone said that you should use heade

相关标签:
7条回答
  • 2020-12-09 07:45

    i think this will help you

    content of .htaccess

    ErrorDocument 404 /error.php
    ErrorDocument 400 /error.php
    ErrorDocument 401 /error.php
    ErrorDocument 403 /error.php
    ErrorDocument 405 /error.php
    ErrorDocument 406 /error.php
    ErrorDocument 409 /error.php
    ErrorDocument 413 /error.php
    ErrorDocument 414 /error.php
    ErrorDocument 500 /error.php
    ErrorDocument 501 /error.php

    error.php and .htaccess should be put in the same directory [in this case]

    0 讨论(0)
  • 2020-12-09 07:47

    For PHP >= 5.4 you can use a simpler function like this : http_response_code(404);
    PHP Documentation

    0 讨论(0)
  • 2020-12-09 07:48

    You could try specifying an HTTP response code using an optional parameter:

    header('HTTP/1.0 404 Not Found', true, 404);
    
    0 讨论(0)
  • 2020-12-09 07:50

    Use these codes for 404 not found.

    if(strstr($_SERVER['REQUEST_URI'],'index.php')){
      header('HTTP/1.0 404 Not Found');
      readfile('404missing.html');
      exit();
    }
    

    Here 404missing.html is your Not found design page. (it can be .html or .php)

    0 讨论(0)
  • 2020-12-09 07:52

    Another reason may be if you add any html tag before this redirect. Look carefully, you may left DOCTYPE or any html comment before this line.

    0 讨论(0)
  • 2020-12-09 07:59

    After writing

    header('HTTP/1.0 404 Not Found');
    

    add one more header for any inexisting page on your site. It works, for sure.

    header("Location: http://yoursite/nowhere");
    die;
    
    0 讨论(0)
提交回复
热议问题