mod_perl logo perl icon
no previous pagepage up: What is mod_perl?no next page

Example PerlTransHandler






Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

By Lincoln Stein, Doug MacEachern
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

By Dave Rolsky, Ken Williams
mod_perl2 User's Guide

mod_perl2 User's Guide

By Stas Bekman, Jim Brandt
Practical mod_perl

Practical mod_perl

By Stas Bekman, Eric Cholet
The mod_perl Developer's Cookbook

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Kobes
mod_perl Pocket Reference

mod_perl Pocket Reference

By Andrew Ford


Table of Contents

Using mod_perl to rewrite URLs

Anyone that's looked at web logs will quickly see the usefulness of this little mod_perl script. It catches all requests for favicon.ico and rewrites the request to point to a valid location. No more logs full of 404 errors.

This example is adapted from the mod_perl Developer's Cookbook, chapter 12.

  file:Cookbook/Favicon.pm
  ------------------------
  package Cookbook::Favicon;
  
  use Apache::Constants qw(DECLINED);
  use strict;
  
  sub handler {
      my $r = shift;
  
      $r->uri('/images/favicon.ico')
          if $r->uri =~ m!/favicon\.ico$!
  
      return DECLINED;
  }
  1;

And configure in httpd.conf with:

    PerlModule Cookbook::Favicon
    PerlTransHandler Cookbook::Favicon

Although this example could easily be accomplished with Apache's mod_rewrite module, this example demonstrates how easy it is to rewrite URLs programatically, using Perl.

« back




TOP
no previous pagepage up: What is mod_perl?no next page