Java Mailing List Archive

http://www.apache-httpd.com/

Home » modperl.perl »

rewrite url in modperl

moli

2010-02-01

Replies: Find Java Web Hosting

Author LoginPost Reply
Hello,

I have this modperl handler:

use Apache2::RequestRec ();
use Apache2::Connection ();
use Apache2::RequestUtil ();
use Apache2::ServerUtil ();
use Apache2::Log ();
use Apache2::Request ();

use Apache2::Const -compile => qw(OK FORBIDDEN);

sub handler {

  my $r = shift;
  my $q = Apache2::Request->new($r);
  my $s = Apache2::ServerUtil->server;

  # get customer's ip
  my $ip = $r->connection->remote_ip;

  if ( is_valid_ip($ip) ){
    return Apache2::Const::OK;

  } else {
    $s->log_error("$ip FORBIDDEN");
    return Apache2::Const::FORBIDDEN;
  }
}


which verify the client's IP and return OK if ip is valid, otherwise
return FORBIDDEN.

Now I have to rewrite the requested url to another one, for example,

when customer requests:
http://example.com/path/12345_YWJjZGVmZw.mp4

the handler will remove the string after "_" (includes the "_"
itself), so the url will become:

http://example.com/path/12345.mp4

(because only 12345.mp4 is a real file on the filesystem,
12345_YWJjZGVmZw.mp4 is just virtual.)

How to implement that?

Thanks for your kind helps.
©2008 apache-httpd.com - Jax Systems, LLC, U.S.A.