On Monday 01 February 2010 14:10:17 [email protected] wrote:
> 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?
>
I think you know you can return Apache2::Const::REDIRECT or
Apache2::Const::HTTP_SEE_OTHER along with a location header and have the
browser do the redirect. But I think that is not what you want, right?
If you don't want the browser to see the actual location of the mp4 file then
you need $r->internal_redirect:
use Apache2::SubRequest ();
...
if ( is_valid_ip($ip) ){
$r->internal_redirect('/path/12345.mp4');
return Apache2::Const::OK;
Torsten