On Mon, Aug 08, 2005 at 01:54:08AM -0700, David Blomstrom wrote: > --- Brian Candler <B.Candler@xxxxxxxxx> wrote: > > > (2) using an external rewriting process. Lookup > > syntax is the same as above, > > but you write an external script (e.g. in perl or > > whatever language you're > > happy with) which performs the lookup in whatever > > way you like, e.g. from a > > hash in memory, from a SQL database etc. > > So you're suggesting two separate ways of doing this, > one with Apache mod_rewrite and (2) with a different > software program, right? About the only related > software programs I'm familiar with are PHP and MySQL. > But from your last sentence, it sounds like this > couuld be done with a MySQL database. Not exactly - I'm suggesting doing this with mod_rewrite but with an external rewriting program. Something like this (untested): RewriteMap mapper prg:/usr/local/bin/mapper RewriteCond ${mapper:$1} ^(.+)$ RewriteRule /stack/(.+)$ %1 [R,L] where /usr/local/bin/mapper is a program like this in a language of your choice: #!/usr/bin/perl %mappit = ( "top_predator" => "/articles/wolf", "canis_lupus" => "/articles/wolf", ); while (<>) { chomp; $ans = $mappit{$_} || "NULL"; print "$ans\n"; } The RewriteLogic says: - the URI is matched against /stack/(.+)$ - If it matches, $1 is set to the parenthesised expression and we continue processing the RewriteCond - the RewriteCond passes $1 to the mapper, and the result is matched against the RHS regexp. The regexp .+ matches any non-empty answer. It is captured by the parentheses as %1 - If that match succeeded, then the RHS rewrite is done, substituting the URI with %1, turning it into a redirect, and stopping ruleset processing. Each Apache worker will start up an instance of the mapper program as a child, and pass messages to it for the ${mapper:...} lookups. Clearly this program can use whatever lookup mechanism you like: DBI for SQL lookups, for instance. You might not want the overhead of that on every lookup, but you could always select the whole table into a Perl hash, and then answer queries from the hash as above. After changing the SQL table you'd need to restart Apache to pick up the new values. Regards, Brian. --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx