print "Content-type: text/html\nstatus: 404\n\nHello, whirled.";
And here's the excert from my log file after I successfully load test.cgi in a browser and see the output:
"GET /test2.cgi HTTP/1.1" 200 308 "-" "Mozilla/5.0...
I've tried it with and without a space after "Content-type:", and I've tried both "Status:" and "status:".
What am I doing wrong?
HTTP/1.1 200 OK
Date: Sun, 29 Jan 2006 22:22:22 GMT
Server: Apache
...
Not sure offhand how to set this using "raw" CGI, something like
print "404 Not Found\nContent-type: text/html\n\nHello, whirled."; print header(’404 Not Found’); One odd thing I found in my testing is that if I request a non-existent directory (e.g., domain.com/foo) then my log shows a 404. But if I request a non-existent *page* (e.g., domain.com/foo.html) then it shows 200. This is true even if I rename the .htaccess file to make sure there's no interference from that.
If you're on Apache server, add the following line to your .htaccess file:
ErrorDocument 404 /cgi-bin/test.cgi
Then try to access a non-existant file off your server. You should be redirected to the script and a proper 404 error response should be found in your error logs.
If there's no record in the database, I want to return a 404 error. It's not enough to print an error page, because I want the requesting client to know that the page no longer exists (especially if it's a bot), and I want failed requests to show up in my logfiles as 404's.
So I don't think your suggestion of requesting a non-existent page will work for me. Right now a request for *any* url, valid or not, will return an error page with a 200 status code attached.