Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2010, 09:39 AM   PM User | #1
Pennimus
Senior Coder

 
Join Date: Jul 2005
Location: UK
Posts: 1,051
Thanks: 6
Thanked 13 Times in 13 Posts
Pennimus is on a distinguished road
Custom Error Page That Returns 200 HTTP Response?

The following is taken from a thread on SEOmoz.org that I have been participating in:


Quote:
Originally Posted by Me
Interesting article, but are you sure you can force a 200 HTTP response from a custom error page?

I've tried this on two sites and, while I can force a 301 without any problems, in the case of a 200 I simply get a 404.

Perhaps there is some server configuration to alter in order to allow this to work?
Quote:
Originally Posted by OP
Yes...you must set the status in the header BEFORE outputting any HTML at all to the client though.
Quote:
Originally Posted by Me
That's what I've been doing.

Exact contents of my test custom 404 page:

PHP Code:
<?php
  header
('HTTP/1.1 200 OK');
?>

Bailed!
Outcome:
URL=http://www.board-crazy.co.uk/nonexistentpage
Result code: 404 (NotFound / Not Found)

Obviously I don't disbelieve you, just trying to figure out what your server is doing differently!
Quote:
Originally Posted by OP
OK, figured out how to make this work in Apache. Here's my 404 page that returns a 200. The key is to call ob_start() and ob_end_flush() to make sure the header bit with the status is NOT sent before we can override it with our header() call:

PHP Code:
<?php    
  ob_start
();    
  
header('HTTP/1.1 200 OK'true200);
?>

[snipping out the HEAD, BODY tag etc. to avoid getting important stuff lost in the noise....]

<?php     
  ob_end_flush
(); 
?>
As you can see, in this convo I'm having quite a lot of difficulty achieving an effect that the blog post in question talks about, namely forcing a 200 HTTP response from a custom 404 page. This is for the purposes of custom URL rewriting.

The poster has been very helpful in following up my comments but I've now tried the last suggestion using ob_start and ob_end_flush and still can't get it to work.

Does anyone here know why this might work for some sites but not others? Any alternative suggestions for getting it to work?
Pennimus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:12 PM.


Advertisement
Log in to turn off these ads.