Welcome to WebmasterWorld Guest from 54.166.152.121

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Page Header Status

     
12:06 pm on May 28, 2013 (gmt 0)

10+ Year Member



I have a very old php script (forum) running which I need to fix in a way to return the correct Apache status. The script returns a 302 status for all 404 pages. I would like to return a 404 for all pages which no longer exist.

This is a problem especially with the Google Webmaster tools showing all these as soft 404s errors.
12:44 pm on May 28, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Use the HEADER directive. This must be sent before any other output to the browser. The extra code will need to be very near the beginning of your PHP script.
8:46 pm on May 31, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



In the past when looking up the 404 header (I can't remember the syntax for everything :) ) I've seen people advise the following:

header('HTTP/1.0 404 Not Found', true, 404);
header('Status: 404 Not Found');

I'm not sure if having them both really makes any difference though.
8:51 pm on May 31, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I think
header("HTTP/1.0 404 Not Found");

is enough.
More info: [php.net...]
9:46 pm on May 31, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



I think it depends on your php version. Even if you're on shared hosting, they should say somewhere. There's one form that goes

:: shuffling papers ::

 if (function_exists('http_response_code'))
{ http_response_code(404); }
else
{ header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found"); }
include ($_SERVER['DOCUMENT_ROOT'] . "/boilerplate/missing.html");


The last line is cut-and-paste from my own vaguely analogous code. This part is crucial-- the task, that is, not the exact filename-- because the 404 doesn't come from the server, so the 404 page won't be shown unless you explicitly code for it. If you leave it out, humans will see a perfectly blank screen. This is unnerving when it happens ;)
12:22 pm on Jun 5, 2013 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I would like to return a 404 for all pages which no longer exist


You may also consider a 410 Gone. In the Apache conf you merely use:
Redirect gone /path/to/no-longer-exists.htm

More information:
[w3.org...]
 

Featured Threads

Hot Threads This Week

Hot Threads This Month