Support » Plugins » Prevent 404 headers from being sent

  • Resolved lonewolfonline


    I have written custom code into my 404.php which attempts to work out what the user was after and show the correct information on the page. From the users point of view no error has occurred and the 404 page is seamless from what they were after, except that 404 headers are still sent = bad.

    How do I turn off 404 headers if the code in my 404.php can find what the user was after?

    I am also using this technique to effectively allow parameters to be passed to pages, but again 404 headers are being sent.

    /pictures/ is a page in my blog.

    /pictures/album-name/ is not a page so results in a 404.

    .htaccess rules rewrite this behind the scenes to /pictures/?a=album-name

    My 404 page triggers and detects the user was after an album so includes page.showalbum.php which reads the album parameter and shows the pictures.

    Works perfect except 404 headers are being shown.

    For this page I am looking at isset($HTTP_GET_VARS['a']) if its true then I show the gallery so don’t send 404 headers, otherwise just do a normal 404.

    Is there a hook that can be used to tell wp not to send 404 header? I cannot put header(“Status: 200”); in the first line of header.php as it reports that headers have already been sent.

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Roger Theriault


    Sorry, this is a bad idea.

    What will happen if a search engine follows a bad link? It will index the bad link and result message (possibly even if you insert a nofollow, noindex meta in the header). Search engines can’t understand the text they see on your page like most humans can. That’s why there are status codes – to represent that the page requested and the result received is not an official page, in the case of 404.

    Google actually appears to be testing this… their webmaster tools will complain if they detect a 404 page that is sending a 200 header.

    If you want to redirect, set up redirect rules and logic within the existing WordPress actions and filters, and avoid your 404 page. If you want to receive parameters, there are WordPress functions that you can use to set that up, such as add_rewrite_endpoint().

    But if you get to the 404 page template, a 404 header should logically be sent back.



    Thanks RogerTheriault,

    I am actually very close to having a proper fully working method for passing parameters to pages without the 404 page.

    I agree with what you are saying about search engines, maybe i’ll just redirects as you suggest. I was just trying to help the user.

    Anyway, I am working on a solution using page parameters for the picture gallery section which is coming along very nicely.

    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prevent 404 headers from being sent’ is closed to new replies.