Skip to page content or Skip to Accesskey List.


Main Page Content

Simulating Apache Asis Feature With Very Simple Cgi

Rated 3.89 (Ratings: 0)

Want more?


Robert Marder

Member info

User since: 29 Oct 2007

Articles written: 1

Apache's asis feature, provided by mod-asis, is a very simple way of sending static HTTP headers along with static content. Many installations of Apache have this disabled (the default) and those of us not on Apache are out of luck. This combination has led to this simple and useful feature being overlooked by most web developers.

Following is a simple method of simulating the behavior of asis using CGI. While CGI does tend to be slower, the only speed loss here is how long it takes the server to launch a small program since the content itself is static. For performance and simplicity, we will be using the tail program, which is included in virtually all unix-like systems. Here is the shebang line you would add to the start of your asis file:

#!/usr/bin/tail --lines=+2

The above command executes tail and the --lines=+2 indicates that we want the first line to be skipped. This is needed because the first line is the shebang line. In other parsed CGI languages the # would be treated as a comment, but tail does not parse the text, it just outputs it. If this wasn't an issue then we could just use the cat command instead.

Here is an example use of our simulated asis feature. Here we have this file at

#!/usr/bin/tail --lines=+2

Content-Type: text/html


It serves as a redirect for us. Other uses for this feature include under construction pages that you do not want cached, refreshing pages that reference client side script that changes often or is somehow dynamic (like adverts or status page), and sending or clearing a cookie (and possibly redirecting or refreshing).

Please note that we are not restricted to using tail. We could use dog (an enhanced replacement for cat) like so:

#!/usr/bin/dog -l 2- -

If you are on a Windows server, then you are likely out of luck because Windows doesn't have simple command-line tools like tail included (they might be found by searching the net, however). If you were on Windows this likely would not be ideal anyway because CGI is much more expensive on Windows than on unix-like systems, and because Windows doesn't parse the shebang line.

So, we have a simple, fairly efficient way to transform dynamic pages that send headers while the rest is echo or print statements using a CGI solution that is not slow by any means.

The access keys for this page are: ALT (Control on a Mac) plus: is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.