How do I create a CGI-based redirect page?

A redirect page is one that, well, redirects the user to another page upon entering, and is commonly used when a site or certain webpages have changed location. In the past, we looked at how to use either HTML and JavaScript to construct it; in this short tutorial, allow us to cap things off by illustrating a third technique- CGI.

A CGI based redirect page is required whenever the original page to be redirected from is a CGI document. No JavaScript or HTML code will do, since CGI documents are interpreted by the server, and requires actual CGI codes in them.

Without further adui, here's the CGI equivalent of a HTML/JavaScript redirect page:


print "Location:\n\n";

Simply copy the above two lines into your text editor, replace the part in red with the destination URL of your choice, and save it as the file name of the old CGI document (ie: ""). Also, make sure the first line of the script, #!/usr/bin/perl, is the correct path to the Perl interpreter on your server. In some cases, it is #!/usr/local/bin/perl instead.

As an example of a CGI redirect page in action, go to old forum URL It automatically takes the visitor to our new forum location (, and uses exactly the code above to accomplish this.

Congratulations, you are now officially a page redirect Jedi!