Advertisement
Guest User

Untitled

a guest
Aug 11th, 2009
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.55 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Getopt::Long;
  4. my %opts = ();
  5. my %redirects = ();
  6. $|=1;
  7.  
  8. GetOptions (
  9.       "F:s" => \$opts{F},
  10.       "debug"=>\$opts{debug}
  11. );
  12.  
  13. my @rules = ();
  14.  
  15. print "DEBUG: opening " . $opts{F} . "..." if defined($opts{debug});
  16. open (F, $opts{F}) or warn "Couldnt open " . $opts{F} . "$@\n";
  17. print "done.\n" if defined($opts{debug});
  18.  
  19. while (<F>){
  20.   chop;
  21.   my $a;   my $u1;   my $u2;
  22.  
  23.   if ($_ !~ /^\s*#/){
  24.     my $l = "";
  25.     print "DEBUG: reading <$_>\n" if defined($opts{debug});
  26.     ($a, $u1, $u2) = split (/\s+/, $_, 3);
  27.     print "DEBUG: tokenized [$a] [$u1] [$u2]\n" if defined($opts{debug});
  28.     if ($a eq "redirect"){
  29.       $l = "301:";
  30.       print "DEBUG: action is redirect! +301\n" if defined($opts{debug});
  31.     }
  32.     elsif ($a eq "redirect_temporary"){
  33.       $l = "302:";
  34.       print "DEBUG: action is redirect_temporary! +302\n" if defined($opts{debug});
  35.     }
  36.     $redirects{$u1} = $l.$u2;
  37.     print "DEBUG: arrayed <" . $redirects{$u1} . ">\n" if defined($opts{debug});
  38.   }
  39. }
  40. print "DEBUG: closing " . $opts{f} . "..." if defined($opts{debug});
  41. close (F);
  42. print "done.\n" if defined($opts{debug});
  43.  
  44. my @X = ();
  45.  
  46. while (<>){
  47.   chop;
  48.   print "DEBUG: read $_\n" if defined($opts{debug});
  49.   @X = split;
  50.  
  51.   my $l = "";
  52.   my $u = $X[0];
  53.  
  54.   print "DEBUG: url [$u]\n" if defined($opts{debug});
  55.  
  56.   $u = $redirects{$u} if (defined($redirects{$u}));
  57.     # redirect -> 301
  58.     # redirect_temporary -> 302
  59.     # map -> ......
  60.  
  61.   print "DEBUG: we redirect to: [$l$u]\n" if defined($opts{debug});
  62.   print $u . "\n";
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement