#!/usr/bin/perl # The third-simplest redirector on the planet, written 9/22/5 by Aaron. # It used to be the case that subdomains of columbia villages were reached via URLs like # http://www.columbiavillages.org/subdomain_name; now they're proper subdomains, like # http://subdomain_name.columbiavillages.org/. Since they've been the old way for so long, # and since it's such a bloody pain in the neck to find every instance of the old style and # replace it when there are things like variable interpolation to consider, and so that the # old links which have been published won't go bad, I've created this simple redirection tool. # It's not so simple to set up, though. First you need to create symlinks for each of the old # directory names to this script; then you need to tell the server to follow those symlinks, # and to execute what it finds there as Perl code. The last bit is the trickiest; here's the # Apache httpd.conf snippet I used to make it happen: # # Yeah, that's a long regex. It matches anything ending in CGI, or any of the names in the list # so long as they're preceded by beginning-of-line and followed by end-of-line; that's so that # you can have the kingscontrivance symlink in the same directory as a file named # kingscontrivance.html, for example, and have the server do the right thing in each instance. # It's also important to preserve query strings in instances where they exist, which is the # purpose of all the $ENV{QUERY_STRING} rigamarole below. This way, anything including a GET # request which goes through this redirector will work properly; I'm not sure about a POST, # although I suspect that if the browser posts something and gets a Location: header back it # should do the post again to the url specified in the header. Not sure about that and I don't # think it matters in this case, so I haven't tested it. my $name = $ENV{SCRIPT_NAME}; $name =~ s/[^A-Za-z]//g; my $path = $ENV{PATH_INFO} or ''; my $query = $ENV{QUERY_STRING} or ''; $query = '?' . $query if $query; print "Location: http://$name.columbiavillages.org$path$query\n\n";