Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Getopt::Long;
- my %opts = ();
- my %redirects = ();
- $|=1;
- GetOptions (
- "F:s" => \$opts{F},
- "debug"=>\$opts{debug}
- );
- my @rules = ();
- print "DEBUG: opening " . $opts{F} . "..." if defined($opts{debug});
- open (F, $opts{F}) or warn "Couldnt open " . $opts{F} . "$@\n";
- print "done.\n" if defined($opts{debug});
- while (<F>){
- chop;
- my $a; my $u1; my $u2;
- if ($_ !~ /^\s*#/){
- my $l = "";
- print "DEBUG: reading <$_>\n" if defined($opts{debug});
- ($a, $u1, $u2) = split (/\s+/, $_, 3);
- print "DEBUG: tokenized [$a] [$u1] [$u2]\n" if defined($opts{debug});
- if ($a eq "redirect"){
- $l = "301:";
- print "DEBUG: action is redirect! +301\n" if defined($opts{debug});
- }
- elsif ($a eq "redirect_temporary"){
- $l = "302:";
- print "DEBUG: action is redirect_temporary! +302\n" if defined($opts{debug});
- }
- $redirects{$u1} = $l.$u2;
- print "DEBUG: arrayed <" . $redirects{$u1} . ">\n" if defined($opts{debug});
- }
- }
- print "DEBUG: closing " . $opts{f} . "..." if defined($opts{debug});
- close (F);
- print "done.\n" if defined($opts{debug});
- my @X = ();
- while (<>){
- chop;
- print "DEBUG: read $_\n" if defined($opts{debug});
- @X = split;
- my $l = "";
- my $u = $X[0];
- print "DEBUG: url [$u]\n" if defined($opts{debug});
- $u = $redirects{$u} if (defined($redirects{$u}));
- # redirect -> 301
- # redirect_temporary -> 302
- # map -> ......
- print "DEBUG: we redirect to: [$l$u]\n" if defined($opts{debug});
- print $u . "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement