Changing HTTP or CGI Response Code

200 OK, 404 Not Found, etc. These are the standard HTTP response code (they may also be called CGI status code). Say, you want to replace standard response code 404 to a custom response code (e.g. 999) for testing or debugging purpose, you can do it easily with Apache Web Server.

Edit the “http.conf”. In Debian, it’s full path is “/etc/apache2/http.conf”. Add in the following lines:

ScriptAlias /cgi-bin/ /var/www/cgi/
ErrorDocument 404 /cgi-bin/999.pl

The first line indicates the whereabout of the CGI script directory.
The second line instruct the Apache to run the “999.pl” script when a HTTP 404 is encountered

Create a custom CGI script in the “/var/www/cgi” directory. Name the script “999.pl”. The content of the script is listed below:

Background:
In work, my system (a web service) has been accused of sending HTTP response code 503 to one of the client but the requests were actually processed. The response code 503 (service not available) could never have been sent by my system if the requests had been accepted and processed. My guess is: there are some gateways that sit between the client and my system that returned 503 to the client yet forwarded the requests to my system. To justify my idea, I use the above method to replace 503 response code with 555 (a non-existing code). After the change, the said client is still receiving response code 503. Now, I can be sure the fault is not with my system. The sad part is, the person in charge of the client system is still not believing that the HTTP 503 is not from my system.