Forum Moderators: coopster

Message Too Old, No Replies

Generating an Error 404

can php invoke server response codes?

         

haxored

1:42 pm on May 7, 2004 (gmt 0)

10+ Year Member



I'm working on a CMS using mod_rewrite to handle URLs. Anything within my cms dir (/cms) is passed to index.php. I want bad URLS (/cms/this/is/invalid/)
to show a 404 page -- and STILL register as an actual 404 error. Right now, I'm just making PHP redirect to /404 (a nonexistent url) so it actually registers a 404 error. I don't think that is ideal for search engines though -- that and I lose the HTTP_REQUEST environment variable, so looking at the page, you won't know which link actually generated the 404 error.
Is there some way I can get PHP to invoke a 404 error without redirecting to a nonexistent URL?

httpwebwitch

2:31 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make a nice 404 page for your visitors, and put this at the top:
header("HTTP/1.0 404 Not Found");

that's all it takes.

after that, you can do any logging functions you want, display an error message to the user, or whatever. With my 404 page, I have mail sent to my Inbox whenever there's a 404 request; in that mail I include the whole $HTTP_SERVER_VARS collection which helps me debug broken links.

[edited by: httpwebwitch at 5:06 pm (utc) on May 7, 2004]

haxored

3:01 pm on May 7, 2004 (gmt 0)

10+ Year Member



Blessed be! Thank you! I had a feeling it was a header thing, but I couldn't find which one it was!