One of the Selector components

Using the Host Selector in a live environment

In an environment where more than one site is hosted on the some Cocoon instance, you'll probably use a different domain name for each site. To make this possible, the host selector is used. The host selector selects a certain pipeline according to the value of the host name. This is the part of the URL between 'http://' and the first slash, such as '' in '', consisting of both the subdomain (www) and the domain itself (

When a request comes in, the host name of the URL requested is passed on to Cocoon. Within Cocoon it is then possible to conditionally execute pipelines depending on the host name using the host selector.

For example; we have a webserver running Cocoon with the following five host names:


In this case we would have bought the domains '' and '' from some domain name registry service. The DNS routes '*' and '*' to the webserver running Cocoon. Tomcat is configured to send all requests to the Cocoon webapp, regardless of the host name. Now it is up to Cocoon to decide what to do when a request comes in.

It is a good use to let the main sitemap of Cocoon receive all requests, and pass the request to a subsitemap depending on the host name. For each host name, there is a sitemap defined that acts as the main sitemap for that site (the hostsitemap). You can let more host names share the same hostsitemap, too.

The host selector definition assigns internal names for use inside the sitemap to different host names. A simple <map:select> can then use this internal name to pass execution the correct pipeline.

The following is defined in the <map:components> section of the main sitemap:

        <map:selector name="host" logger=""
                <host name="jakarta-apache" value=""/>
                <host name="xml-apache" value=""/>
                <host name="www-apache" value=""/>
                <host name="www-apache" value=""/>
                <host name="www-foobar" value=""/>

As you can see, "" and "" share the same internal name, "www-apache". In this way, we can use the same hostsitemap for both sites (which will make them identical).

N.B. You wouldn't want to do this in a production environment; it would cause Google to index your site twice. "So what!" you say. Well, Google now penalizes sites with duplicate content... so you just reduced your sites ranking! Better to issue a permanent redirect response from one site to the other. - DavidLegg

You could also add a new host selector to the www-apache hostsitemap, which then again destinguishes between '' and '' using the same internal names.

In the main pipeline of the main sitemap the actual UnderstandingCocoonMounts is done:

<map:select type="host">
        <map:when test="jakarta-apache">
                <map:mount uri-prefix="" 
                                src="file://home/sites/jakarta-apache/sitemap.xmap" />
        <map:when test="xml-apache">
                <map:mount uri-prefix="" 
                                src="file://home/sites/xml-apache/sitemap.xmap" />
        <map:when test="www-apache">
                <map:mount uri-prefix="" 
                                src="file://home/sites/www-apache/sitemap.xmap" />
        <map:when test="www-foobar">
                <map:mount uri-prefix="" 
                                src="file://home/sites/www-foobar/sitemap.xmap" />

Notice that the uri-prefix is left empty in every <map:mount>. This lets the hostsitemap start with the root of the URI, directly after the host name (i.e. "index.html" in "").

It's another good use to put all the hostsitemaps in different directories on the server. Every hostname-directory can hold it's own set of stylesheets, resources, sitemaps, etcetera, allowing concurrent development on the different sites.

Using the cocoon:/ CocoonProtocolExample inside any sitemap will point to a pipeline inside the sitemap itself. However, when using cocoon:// inside a hostsitemap, you point to the root sitemap, which will automatically forward the request to the hostsitemap corresponding to the host name. This means that you can use cocoon:// protocol from within any subsitemap, no matter how deep it's nested, to refer to the hostname-sitemap.

The following table shows the host selector process of the example above:


Host name

Internal name


URI passed to the Hostsitemap||||www-apache||file://home/sites/www-apache/sitemap.xmap||index.html||||www-apache||file://home/sites/www-apache/sitemap.xmap||foo/bar/index.html||||www-apache||file://home/sites/www-apache/sitemap.xmap||index.html||||jakarta-apache||file://home/sites/jakarta-apache/sitemap.xmap||foo/bar/index.html

HostSelector (last edited 2009-09-20 23:40:20 by localhost)