For dynamic systems sometimes we rely on the use of a 404 redirect to manage exceptions. The problem with this is that sometimes we are caught between a rock and a hard place. The rock, is the browser receiving the 404 header before we have a chance to tell it that it’s not actually a 404.
Take this example of a 404 apache redirect:
header(”HTTP/1.0 200 OK”);
echo “I like cheese and I like cake.”;
What’s the problem? Nothing at this point and this is because browsers are able to quickly read and understand the new header before it pushes out the content to the browser window. It’s the same when you deal with streaming images too, you can:
header(”HTTP/1.0 200 OK”);
header(”content-type: image/png”);
print_r(file_get_contents(’my.png’));
This will work okay too, but what about when your dealing with cookies? It’s hard enough for a browser to set/forget cookies when you tell it too, but some browsers are definately not happy when you try and set a cookie on an image - I guess in their defense, who needs a cookie for an image? Well, we do!
A quick way around this, is to use mod_rewrite, within apache instead. This will then allow you to get a 200 OK by default, so your not confusing the situation when you send in multiple headers and then a cookie all in one transaction. That way, some of the less-coder-friendly browsers will be able to pick it up in a snap.
As soon as we work out exactly why - we will let you know!