The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Apache::RedirectDBI - Redirect requests to different directories based on the existence of a user in one or more database tables


# in httpd.conf

PerlModule Apache::DBI Apache::RedirectDBI

<Location /path/to/virtual/directory> SetHandler perl-script PerlHandler Apache::RedirectDBI PerlAuthenHandler Apache::AuthenDBI

    PerlSetVar Auth_DBI_data_source     dbi:Oracle:CERT
    # :
    # and other Auth_DBI_* variables
    # :

    PerlSetVar RedirectDBI_data_source dbi:Oracle:CERT
    PerlSetVar RedirectDBI_username    nobody
    PerlSetVar RedirectDBI_password    nobody
    PerlSetVar RedirectDBI_location    /path/to/virtual/directory
    PerlSetVar RedirectDBI_default     /path/to/virtual/directory.1
    PerlSetVar RedirectDBI_table2uri   "t1 /directory.2 t2 /directory.3"

    AuthName "Realm"
    AuthType Basic
    Require  valid-user


Apache::RedirectDBI allows you to create a virtual path in your document hierarchy.

All requests for access to this virtual path should require a username and password to access. When the user attempts to access this virtual path their username is looked up in one or more database tables. The table in which the username is found in determines the physical path from which files are served.

Files are served to the user without the URL changing, so they never know that they have been redirected elsewhere.

The user is redirected to a default location if they are not in any of the database tables.


First, define the virtual location that a user will see. You must also create other directories from which files will be served.

For example, specify /dir as the virtual directory, and have $DOCROOT/dir.1, $DOCROOT/dir.2 and $DOCROOT/dir.3 as three possible directories that files will be served from, depending on the table that lists the user.

    <Location /dir>

The different configuration directives in httpd.conf have the following meanings;


A DBI identifier for the data source that contains the tables that will be used to determine which directory to send the user to.


The username to use when connecting to the data source.


The password to use when connecting to the data source.


The same path as used in the <Location ...> section of this configuration.


Path (relative to the document root) from which files will be served if the user does not exist in any of the database files.


A string containing white space seperated elements. Each element is part of a pair. The first element in each pair is the name of the table in the data source that contains a list of usernames. The second element is the directory (relative to the document root) from which files will be served if the user is in this table.


The tables listed in the RedirectDBI_table2uri string must contain one or more columns. One of these columns must be called name, and must contain the usernames.

These tables do not necessarily have to be real tables. If the backend database supports it then they could be views. This allows for a lot of flexibility in specifying the criteria for the inclusion of a user in the table.


  • The column that contains the usernames must be called name. If your tables do not have a column with this name, create a view of the table that renames the appropriate column to name and use the view when configuring this module.

  • If the same username exists in more than one of the listed tables, the location for the first table they are found in is used. Tables are searched in the same order as they are listed in the configuration file.

  • It is assumed that the database connection to read the tables will always succeed.


perl(1), Apache(3), Apache::DBI(3)


Mike Smith (

Original Apache module

Nik Clayton (

Original CGI scripts which this replaces, and this documentation.