Welcome to WebmasterWorld Guest from 54.146.5.196

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Page Header Status

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

Junior Member

10+ Year Member

joined:Jan 15, 2004
posts: 68
votes: 0


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)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:945
votes: 0


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)

Senior Member

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

joined:Aug 7, 2003
posts:4783
votes: 0


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

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

Senior Member from US 

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

joined:Apr 9, 2011
posts:13682
votes: 446


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 June 5, 2013 (gmt 0)

Administrator

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

joined:July 31, 2003
posts:12547
votes: 2


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...]
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members