Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using mod_rewrite to redirect all incoming requests to a CGI application. I now need to have the application return a 404 if the requested file isn't found. How can I go about this from my program? The first line sent is the content-type while it's the line before that that usually indicates the status (200/404/500, etc).

share|improve this question
up vote 8 down vote accepted

Use the Status HTTP header. An example in 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>";

When using Perl (and other languages) however, excellent modules like CGI and CGI::Simple exist.

share|improve this answer
Dang, is it really that easy? The CGI tutorial I was following just had me sending the Content-Type line, I had assumed that the Status line was being sent by Apache. I will give this a try tomorrow, thanks! – user11888 Mar 12 '10 at 1:50
Alright, that did the trick. – user11888 Mar 12 '10 at 19:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.