http://myurl.com/aa/index.html
http://myurl.com/aa/bb/index.html
http://myurl.com/aa/foo/index.html
http://myurl.com/cc/index.html
http://myurl.com/cc/dd/index.html
####
aa 1
bb 2
cc/dd 3
cc/ee 4
##
##
RewriteMap mapping txt:mapfile.txt
RewriteRule ^/(.*)/ - [E=TEST_VAL:$1,E=TEST_RESULT:${mapping:$1},NS]
##
##
#!/usr/bin/perl
my $CONFIG_FILE = 'mapfile.txt';
my $config = &get_config;
$| = 1;
while(){
my $pk = lookup($_);
print "$pk\n";
}
sub get_config
{
my $apache_boot_time_message = "$0: Setting up Apache RewriteMap [$CONFIG_FILE]";
print STDERR "$apache_boot_time_message\n";
my %config;
open( CONFIG, '<', $CONFIG_FILE ) or die ("Could not open $CONFIG_FILE: $!");
while(){
chomp;
my $line = $_;
my @line = split('\s+', $line);
$config{$line[0]} = $line[1] unless $line =~ /^#/;
}
close CONFIG;
return \%config;
}
sub lookup
{
chomp;
my $DIR = shift;
my @parts = split( '/', $DIR );
for( 0..$#parts ){
my $dir = join('/', @parts[0..$_]);
return $config->{$dir} if $config->{$dir};
}
return "NULL";
}