I have written a new PerlTransHandler module which I currently calling
Apache::AddHostPath.  It was written to solve a problem I am having in an
application I am writing, however if others think it might be usefull and
there isn't already something out there that does it, I'd be more than happy
to add it to CPAN.

The problem I was trying to solve was that I have 11+ domains, (each of
which may have additional sub-domains besides "www") that I wish to host
from one single apache server and without using Virtual Hosts.  The reason I
don't want to use Virtual Hosts is that I want to be able to inherit things
like images, cgi scripts, stylesheets, javascript, etc.. between domains and
sub-domains without having to do weird symbolic links, or even having to
mess with httpd.conf.  I also want to be able to add domains and sub-domains
without changing the config.  Point the domain and play. :-)

For example not all of the domains are in the same top level domain and I
may want to share the same style sheets between all of my .com domains but
use a different one for .org domains.  Additionally any of the specific .org
domains (or Sub-Domains) could override this stylesheet with their own.

Essentially the module implements Apache's URI translation phase by
attempting to use some or all of the URL hostname and port number as the
base of the URI.

For example:  If a user requested:

http://www.cvsroot.org/images/logo.gif

My module would attempt all of the following combinations, in this order,
until if found the best match (best match being defined as the first one to
return true to (-f $filename or -d $filename)):

$doc_root/org/cvsroot/www/80/images/logo.gif
$doc_root/org/cvsroot/www/images/logo.gif
$doc_root/org/cvsroot/images/logo.gif
$doc_root/org/images/logo.gif
$doc_root/images/logo.gif
$doc_root/org/cvsroot/www/80/images
$doc_root/org/cvsroot/www/images
$doc_root/org/cvsroot/images
$doc_root/org/images
$doc_root/images
$doc_root/org/cvsroot/www/80/
$doc_root/org/cvsroot/www/
$doc_root/org/cvsroot/
$doc_root/org/
$doc_root/
(Failing this it will return DECLINED)

When it finds a match it will tack the portions of the original URI which
had been removed for testing back onto the full path (Thereby preserving any
extra path info, virtual documents, etc...) and sets the $r->filename()

For example, in the above example, if it had selected '$doc_root/org/images'
as the first match, then it would set the $r->filename to
'$doc_root/org/images/logo.gif' even though I already found out it didn't
exist. It does this because of things like extra path info on cgi scripts
and virtual documents returned by content handlers.  Thus relying on the
content handler to do any real validation of the URI & filename.

I have several questions for the mod_perl community:

1) Would this be usefull to the community? (assuming there isn't already a
mod to do this)
2) What about the name?
3) Should I be changing $r->uri() instead, thus allowing additional
TransHandlers? Or maybe setting both?
4) Any ideas for improvement?

The module is already written and seems to work ok.  I still need to write
docs and packaging if I submit to CPAN, but the module itself is only about
25 lines of code.

Thanks in advance,
-Robert Jenks
[EMAIL PROTECTED]

Reply via email to