update actions/github-script from v5 to v7
[m6w6/m6w6.github.io] / _posts / 2005-06-05-moddomaintree.md
1 ---
2 title: mod_domaintree
3 author: m6w6
4 tags:
5 - PHP
6 ---
7
8 Friday evening I put together a tiny [Apache2](http://httpd.apache.org) module
9 simliar to mod_vhost_alias or mod_vd.
10 [mod_domaintree](http://cvs.iworks.at/co.php/mod_domaintree/mod_domaintree.c)
11 maps host names to a filesystem tree. While mod_vhost_alias and mod_vd seem to
12 be more flexible, they seem less useful to me.
13
14 mod_vhost_alias lets you define very precisely which part of the host name
15 maps to which directory but adds odd underscores if the part (number) of the
16 hostname does not exist.
17
18 mod_vd lets you define the numerical amount of host name parts to strip.
19
20 But I **don't want to strip always** one part of the host name like "www" \- I
21 just want to strip the first part of the host name (i.e. www) if it occurs in
22 the sent hostname.
23
24 If you want to try it out, there's nothing more to do then (w)getting
25 [it](http://cvs.iworks.at/co.php/mod_domaintree/mod_domaintree.c?p=1) and
26 running
27 ```shell
28 sudo /usr/sbin/apxs2 -a -i -c mod_domaintree.c
29 ```
30 ## Sample Configuration:
31 ```apache
32 DomainTreeEnabled On
33 DomainTreeMaxdepth 25
34 DomainTreeStripWWW On
35 DomainTreePrefix /sites
36 DomainTreeSuffix /html
37 ```
38
39 ### Mapped Hosts: (accepting "www" as prefix if DomainTreeStripWWW is enabled)
40
41 * company.co.at
42 * sub1.company.co.at
43 * sub2.company.co.at
44 * organisation.or.at
45 * example.at
46 * example.com
47
48 ### Resulting Filesystem Tree:
49 ```shell
50 /sites
51 +- /at
52 | +- /co
53 | | +- /company
54 | | +- /html
55 | | +- /sub1
56 | | | +- /html
57 | | +- /sub2
58 | | +- /html
59 | +- /or
60 | | +- /organisation
61 | | +- /html
62 | +- /example
63 | +- /html
64 +- /com
65 +- /example
66 +- /html
67 ```
68
69 PS: I was very suprised how easy it is to build a simple module for Apache (if
70 you have some templates to look at though). :)