Slaven Rezić > WE_Framework-0.097_03 > WE::Util::Htaccess



Annotate this POD

Module Version: 1.07   Source  


WE::Util::Htaccess - create apache .htaccess files


    use WE::Util::Htaccess;
    WE::Util::Htaccess::create("/var/www/htdocs/.htaccess", $obj_db
                               -authname => "sample",
                               -authuserfile => "/var/www/.htpasswd",
                               -authgroupfile => "/var/www/.htgroup",
                               -inherit => 1,
                               -add => "ErrorDocument 401 /index.html",


This module is used to create Apache .htaccess files from a WE::DB::Obj database. All objects in the database are traversed (or restricted by a filter) and if the object contains a WWWAuth attribute, an entry for the .htaccess file is created.

The WWWAuth attribute should be a string with the following syntax:


If netither "user=" nor "group=" is specified, then a user id is assumed. Example:


means: the users bla and bar and the group foo.

The files .htpasswd, .htgroup and .htaccess are always protected from WWW access, so you can use these names for the user/group files, if you have to store these files in a WWW readable directory.

The create function expects the following arguments:

-authname => $name

The name of the authorization realm. By default it is "WE Authentication".

-authtype => $type

The type of user authentication. By default it is "Basic".

-authuserfile => $file

The path to the .htpasswd file (see WE::Util::Htpasswd). This is required unless set by an entry in the global httpd.conf.

-authgroupfile => $file

The path to the groups file (see WE::Util::Htgroup). This is required if there are any group authentifications in the object database and no entry from the global httpd.conf can be used.

-inherit => $bool

If set to true (default) then inherit folder rights to their children and subfolders.

-filter => sub { my($obj) = @_; ... }

A filter callback for restricting an object or sub-tree. The callback will get the current object as parameter and should return a boolean value. If the returned value is false, then the object is not processed; if it is a folder then the descendants of the folder are not processed either.

-add => $string

A $string to be added to the .htaccess file. An example would be to add an ErrorDocument directive (see

-addfile => $file

Like -add, but read the contents from the named file. It is possible to use -add and -addfile together.

-restrict => $restrict

Alternative restriction scheme. If set, then no access to the WE::DB::Obj database is done. -inherit and -filter are ignored. The $restrict string should be of the form:

    type1 value1 value2 value3; type2 value4 value5 ...

where type is either group or user and value a group or user name.

-getaliases => sub { my($id) = @_; ... }

This should be a code reference which receives the object id as parameter and returns a list of alias names for this page (excluding the supplied id).


Please check the setting of AllowOverride in the global httpd.conf. This directive should be set to All or at least AuthConfig Limit for the web.editor-controlled directories. See also the AllowOverride entry in the Apache documentation:

For a perl-based httpd.conf use something like:

  $Directory{$document_root}{AllowOverride} = "All";


Slaven Rezic -


WE::Util::Htgroup, WE::Util::Htpasswd, WE::DB::Obj, httpd(8).

syntax highlighting: