handling 404 in redirection script

April 28, 2010 at 10:48:29
Specs: Win XP, P4/1GB
I use PHP header("Location: ... function to redirect, rather than .htaccess URL rewriting. This is because some of my URL text searches and changes are rather complex and are very difficult to do in .htaccess, and having good string-handling functions makes it much, much, easier. Anyway, .htaccess kicks any file or directory not found over to my script, and I redirect. My question is, what's the best way to handle genuinely "not found" references? I still have a 404.shtml file but .htaccess is grabbing such files and sending on to my redirection script.

In the redirection script, when I encounter a request that I cannot redirect to a real file, I tried just setting the HTTP status to 404 (with and without header("Location: /404.shtml");), but that gives me a 500 (internal server) error. Is there some way to invoke the real 404.shtml, along with all the reference information (server side includes) needed to display? Should I re-implement 404.shtml in PHP and just directly invoke it from my redirection script? I'm assuming that $_SESSION or $_SERVER contains the information I want to display. Is there a better way to handle this?

Thanks much!

See More: handling 404 in redirection script

Report •

August 19, 2010 at 21:42:17
Try use this,
Header( "HTTP/1.1 404 Page Not Found" );

this for more.

Report •

August 20, 2010 at 09:36:21
Thanks, I think I tried that once, but I'll give it another go, if I decide to go back to using a redirection script (currently I'm trying a CMS).

Report •

Related Solutions

Ask Question