PHP return 404 header?

I am running an forum that checks if the forum URL exists and if not shows an error. How to return 404 error that will then get picked up by the htaccess 404 redirect?

$foruminfo = get_forum($fid);

Could you just check whether the file exist? Does the forum URL have it’s own separate page?

You can’t. Apache will rewrite the request first, and then hand it off to PHP. After that you cant do anything to make Apache back to rewrite again. What you need to do here is send the header yourself using PHP’s header function, and then render a 404 page.

1 Like

Not… strictly true…you could use the header to push the client to a nonexistant page. I wouldnt do it that way (because then the back button becomes an issue), but it’s doable. OP should however do it the way Scallio has outlined.

Thanks guys I tried using:

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

And the browser just shows blank page!

That is expected behavior, as I said in my previous post. If you want a 404 page, you have to let PHP render it.