Mailing List Archive

confirming a handler's behavior
Hi,

I'm starting to make the jump from ePerl-bristled files to handlers, and
this is my first attempt. I'm trying to redirect all requests containing
a particular referrer value to another location. The setup below appears
to do the job, but I'd just like to get a more experienced set of eyes ( or
two or three... ) on it, to make sure it's not going to do anything strange.

I'm also curious as to whether or not this will have a significant effect
on the performance of the server.

Taking all requests containing the referrer value 'http://www.someurl.com"
and pointing them to the home page, passing all other requests through
unaltered...

In httpd.conf, not inside a <Directory> or <Location> container:
PerlHeaderParserHandler Apache::boy_Redirect

The package:

package Apache::boy_Redirect;
use strict;
use Apache::Constants qw( :common MOVED );

sub handler {
my ( $r ) = shift;
if ( $r->header_in( 'Referer' ) eq 'http://www.someurl.com' ) {
$r->content_type( 'text/html' );
$r->header_out( Location => 'http://www.boygenius.com/' );
return MOVED;
} else {
return OK;
}
}
1;

thanks,
Todd
RE: confirming a handler's behavior [ In reply to ]
> Hi,
>
> I'm starting to make the jump from ePerl-bristled files to handlers, and
> this is my first attempt. I'm trying to redirect all requests containing
> a particular referrer value to another location. The setup below appears
> to do the job, but I'd just like to get a more experienced set of eyes ( or
> two or three... ) on it, to make sure it's not going to do anything strange.
>
> I'm also curious as to whether or not this will have a significant effect
> on the performance of the server.
>
> Taking all requests containing the referrer value 'http://www.someurl.com"
> and pointing them to the home page, passing all other requests through
> unaltered...
>
> In httpd.conf, not inside a <Directory> or <Location> container:
> PerlHeaderParserHandler Apache::boy_Redirect
>
> The package:
>
> package Apache::boy_Redirect;
> use strict;
> use Apache::Constants qw( :common MOVED );
>
> sub handler {
> my ( $r ) = shift;
> if ( $r->header_in( 'Referer' ) eq 'http://www.someurl.com' ) {

You might want to do a case insensitive match here. Host names are
case insensitive.

> $r->content_type( 'text/html' );
> $r->header_out( Location => 'http://www.boygenius.com/' );
> return MOVED;
> } else {
> return OK;
> }
> }
> 1;
>

Also check out Apache::RefererBlock, which does that, in a configurable
way.

--
Eric