如何从Apache2 CGI程序返回404

我正在使用mod_rewrite将所有传入请求redirect到CGI应用程序。 我现在需要让应用程序返回404如果找不到请求的文件。 我怎么能从我的程序中解决这个问题? 发送的第一行是内容types,而之前的行通常表示状态(200/404/500等)。

使用Status HTTP标头。 Perl中的一个例子:

 #!/usr/bin/perl use strict; use warnings; print "Status: 404 Not Found\r\n"; print "Content-Type: text/html\r\n\r\n"; print "<h1>404 File not found!</h1>"; 

当使用Perl(和其他语言)时,存在像CGI和CGI :: Simple这样的优秀模块。