This might be considered a continuation of this question.

If I output HTML after my 404 header, It displays properly in IE and FF unless the user has Google bar instaled. If I try

header('HTTP/1.x 404 Not Found');
header("Location: http://www.example.com/?content=404_error");

then I'm getting 302 from the redirect. It seems to overrule the 404

Supposedly if your output is larger than 512 bytes, the toolbar isn't supposed to override the page, but It seems to do it anyway.

I found a setting in Google's Toolbar that said "Provide suggestions on navigation errors". Turning that off provides me with the behaviour I want my visitors to experience. Does anyone know if Google provides a way for a developer to over-ride that setting for all visitors?

| improve this question | | | | |

It looks like are both trying to put a "404 Not Found" status and redirect to the error page contents. The "Location" header is really only valid for 3xx status codes like 301, and 302. I'm surprised that browsers are honoring your request to go to a different location with a 404 status.

To make it work you need to one of two things. Either issue a 302 status instead of a 404 when you redirect to the error page or serve the contents of the error page directly under the 404 status instead of trying to redirect to them.

Here is code for the first

header('302 Moved');
header("Location: http://www.example.com/?content=404_error");

Here is some psuedo code for the second (which is the method that I would use.)

header('200 OK');
#include 404_content
| improve this answer | | | | |
  • Part of my question was meant to indicate that I had just learned that I could not mix the 404 header and the redirect, and if I use the second method that you suggest I get the desired result in browsers that do not have the toolbar installed. For users of the toolbar, the 404 triggers something from the toolbar that over-rides the 404_content. I read that as long as 404_content is over 512 Bytes, the toolbar is not supposed to override it, but it was happening anyway. – TecBrat Feb 13 '13 at 13:55
  • 1
    Matt Cutts - "A lot of the time, a site will return a 404-looking page (not a gag like the site above), but the HTTP status code will be 200 (as if the page was found just fine). We call that a crypto-404. We may look for certain phrases like “file not found,” but if you want to be safe/conservative, I’d doublecheck that your 404 pages really return an HTTP status code of 404, not 200." mattcutts.com/blog/sitemaps-interview/#comment-20432 – DaveP Jun 7 '14 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.