Sunday, June 5, 2005


Friday evening I put together a tiny Apache2 module simliar to mod_vhost_alias or mod_vd. mod_domaintree maps host names to a filesystem tree. While mod_vhost_alias and mod_vd seem to be more flexible, they seem less useful to me.

mod_vhost_alias lets you define very precisely which part of the host name maps to which directory but adds odd underscores if the part (number) of the hostname does not exist.

mod_vd lets you define the numerical amount of host name parts to strip.

But I don't want to strip always one part of the host name like "www" - I just want to strip the first part of the host name (i.e. www) if it occurs in the sent hostname.

If you want to try it out, there's nothing more to do then (w)getting it and running

sudo /usr/sbin/apxs2 -a -i -c mod_domaintree.c

Sample Configuration:

DomainTreeEnabled On
DomainTreeMaxdepth 25
DomainTreeStripWWW On
DomainTreePrefix /sites
DomainTreeSuffix /html

Mapped Hosts: (accepting "www" as prefix if DomainTreeStripWWW is enabled)







Resulting Filesystem Tree:

+- /at
| +- /co
| | +- /company
| | +- /html
| | +- /sub1
| | | +- /html
| | +- /sub2
| | +- /html
| +- /or
| | +- /organisation
| | +- /html
| +- /example
| +- /html
+- /com
+- /example
+- /html

PS: I was very suprised how easy it is to build a simple module for Apache (if you have some templates to look at though). :)

No comments:

Post a Comment