Pregunta

Google's Webmaster Tools is hammering on me to send out proper 404 signals instead of "soft 404s". I found the page generating the errors. I have a website where users create images and the errors appear when Google tries to access images that no longer exist. It seems the developer who coded it had prepared a message in the code for when this happens, but Google is not happy because it is not a proper 404. So, in the middle of the page there's something like this:

if ($empty_page)    {
    echo 'The image you are trying to view is no longer available.';
} else {....renders content...

After Googling the issue, I tried something like this:

if ($empty_page)    {
    header( "HTTP/1.1 404 Not Found" );
    echo 'The image you are trying to view is no longer available.';
} else {....renders content...

That doesn't work.. I don't think? People keep saying that it will generate a header, so I look at the code of the page that gets generated but I don't see '404' anywhere in the code. Is that where it would be? Please help.. I am so lost >_<

Is this a 404 anyway? Should it be a 410 maybe?

¿Fue útil?

Solución

You do not need to see 404 in response page. It's in the headers. You can see your response headers with chrome developer toolbar (or firebug on firefox) in network tab.

This header should do the trick. I suggest putting an exit just after setting the 404 header and echoing message. This will make sure you do not output anything after setting header & printing not found message.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top