Here is the new version, using URI.
However, I had difficulties to see, how the module allows me to seperate ';' seperated parts of the URI (according to o'reillys "HTTP The definitive Guide" called "parameters', opposed to the well known query-string seperated via '?'), so I strip this of with a regex before I construct the URI-Object.

Feel free to comment on this further, I'd appriciate your feedback.

#!/usr/bin/perl -wT # creator : Tom Regner <tomte@tomsdiner.org> # created : Mon 13 Jan 2003 01:29:04 PM CET # version : $Id: apache_rw.pl,v 1.11 2003/07/02 14:09:57 tom Exp $# +copyright : (c) 2002 use strict; use URI; # # change this directive to point to the dir containing the config-file # use lib '/path/to/config/file'; use apache_rw_cfg qw($conf); # loggen? my $DEBUG = 1; $| = 1; # unbuffered IO while (<>) { open(LOG, ">>", "apache_rw.log") if $DEBUG; # change ! my $line = $_; my ($uri, $params, $remainder); $line =~ s/(;.+)//; # strip of ';'-seperated part (session-id and +the like) $remainder = $1; my $luri = URI->new($line); $uri = $luri->path(); $params = $luri->query(); $remainder ||= ''; print LOG $uri . " || " . $remainder . " || " . $params . "\n" if + $DEBUG; my ($new_uri, $new_params); if ($conf->{$uri}->{'url'}) { $new_uri = $conf->{$uri}->{'url'}; my $didIt = 1; my @parm_list = split(/&/, $params); $didIt = 0 if @parm_list == 0; my @new_parm_list = (); if ($didIt) { foreach (@parm_list) { my ($name,$value) = split('=', $_); if (defined($conf->{$uri}->{params}->{$name})) { if ($value =~ m{$conf->{$uri}->{params}->{$name}-> +{regexp}}) { push(@new_parm_list, $conf->{$uri}->{params}-> +{$name}->{name} . '=' . $value); } else { $didIt = 0; print LOG "Param-Value violation" if $DEBUG; } } else { $didIt = 0; print LOG "Param-Name violation" if $DEBUG; } } } if ($didIt == 1) { $line = $new_uri . '?'; $remainder ||= ''; $line .= join('&', @new_parm_list) . $remainder . "\n"; } else { $line = '/' . "\n"; } } else { $line = '/' . "\n"; } close(LOG) if $DEBUG; $line = URI->new($line)->canonical; print $line; } #

regards,
tomte


Hlade's Law:

If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.


In reply to Re: Configurable Apache RedirectMap (now using URI) by Tomte
in thread Configurable Apache RedirectMap by Tomte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.