Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A different approach' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A different approach
Authored by: babbage on Aug 25, '04 01:05:34AM

I stumbled upon the RegisterResource trick last week while reading O'Reilly's Mac OS X Panther Hacks, but their approach depends on two Apache directives for each rule you want to set up -- one with the RegisterResource line, and another with a Redirect statement. I came up with a different approach to publishing URLs that aren't on my server that only requires one Apache rule per published URL.

First, you need a CGI script that takes a URL as an argument and responds with an HTTP directive to go to that URL. Here's one way to do it:

$cat ~/Sites/re.pl
#!/usr/bin/perl -T

use strict;
use warnings;
my $url = $ENV{'QUERY_STRING'} || "http://some/default/page/";

print "Location: $url\n\n";

$ ls -l ~/Sites/re.pl
-rwxr-xr-x    1 www      www           337 Aug 24 20:37 /Users/you/Sites/re.pl
$ ~/Sites/re.pl 
Location: http://some/default/page/

$

If you can get similar behavior as what I show above, you're most of the way there. If you don't like Perl, this script could probably be rewritten in PHP, and can certainly be done in Python or even a Bourne shell script, but I do like Perl, and this was easy to do and I already have my Apache set up to serve mod_perl. YMMV.

Once you have the redirect script in place, set up as many offsite redirects as you want, prefixing them with this redirect script's relative URL, like this:

RegisterResource "Some name" /re.pl?http://some/other/server

Restart Apache and everything will work just fine. Bouncing through your little re.pl script should be fast (most users shouldn't notice the delay), and as a bonus (if you're in to this sort of thing) you get a record of the activity in your Apache log.

Not that there's anything wrong with this <virtualhost> idea, but it seems a lot more complicated than doing it this way... :-)

---
--
DO NOT LEAVE IT IS NOT REAL

[ Reply to This | # ]