NB: These pages were mostly written in 2001 or so. The résumé dates are accurate but the code is aged and unlike whiskey, 8 year-old code doesn't usually taste better. For a look at my current skills and to see my CPAN modules, sample code, and code discussions, please see these pages instead: Perl resources and sample code and PangyreSoft.
Redirect with mod_perl
Social links
View Ashley Pond V's profile on LinkedIn
There would be a sidebar here if we had one.

Other pages


mod_perl is the best thing since sliced bread. It embeds a Perl interpreter in your Apache server. All of the sudden, Perl isn’t too slow to use as your main programming language for your website. It brings the speed of execution to the server that Perl brings to your development time. It rules.

There are more than 2.5 million hostnames serving pages worldwide via mod_perl today. Among the better known is the Internet Movie Database which is one of the oldest www sites (well over 10 years) and serves millions of pages a day.

The task

Here is an example of how to do an internal redirect script.

Many intranets and websites use a single CGI to handle all links to external sites. This is done because the external sites could parse the HTTP_REFERER [sic] to get a pretty good idea of what was being read, done, etc on your site. It gives too much internal information away. Even file names can give away corporate secrets. And privacy is compromised when the next site has information about the page you were just on.

Include in the apache config file, httpd.conf

PerlModule Apache::Redirect # <-- if not built with APACI <Location /goto> SetHandler perl-script PerlHandler Apache::Redirect # what we have to write </Location>
Your new module in @INC path /Apache/Redirect.pm


Anything that comes after the goto/ will be taken as the URL for the redirect.

Now, the admission. This is kind of overkill for a redirect unless you're serious about logging/tracking it. In that case the example isn't so hot because there is no logging going on. This is a snap with mod_perl, though there is no example here. You'd save some server time by having it in mod_perl instead of a simple perl CGI but you could also just have it a shell script if you can hack it up. I can only because Perl is the child of C, sed, awk, and Unix.

Shell script version
In executable file "redirect.cgi"

#!/bin/sh if [ $# == 1 ] then echo Location: $1 echo exit fi echo Content-type: text/html echo echo '<h2>You provided no URL for redirect!</h2>' exit
Usage (now need "?" before the query string)
Search these pages via Google
Text, original code, fonts, and graphics ©1990-2009 Ashley Pond V.