6.4. Type Maps
In the last section, we looked at multiviews as a way of providing language and image negotiation. The other way to achieve the same effects in the current release of Apache, and more lavish effects later (probably to negotiate browser plug-ins), is to use type maps, also known as *.var files. Multiviews works by scrambling together a vanilla type map; now you have the chance to set it up just as you want it. The Config file is as follows:
User webuser Group webgroup ServerName www.butterthlies.com DocumentRoot /usr/www/site.typemap/htdocs AddHandler type-map var DirectoryIndex index.var AccessConfig /dev/null ResourceConfig /dev/null
One should write, as seen in this file:
Having set that, we can sensibly say:
to set up a set of language-specific indexes.
What this means, in plainer English, is that the DirectoryIndex line overrides the default index file index.html. If you also want index.html to be used as an alternative, you would have to specify it -- but you probably don't, because you are trying to do something more elaborate here. In this case there are several versions of the index: index.en.html, index.it.html, index.ko.html, so Apache looks for index.var for an explanation.
Look at ... /site.typemap/htdocs. We want to offer language-specific versions of the index.html file and alternatives to the generalized images bath, hen, tree, and bench, so we create two files, index.var and bench.var (we will only bother with one of the images, since the others are the same).
This is index.var :
# It seems that this URI _must_ be the filename minus the extension... URI: index; vary="language" URI: index.en.html # Seems we _must_ have the Content-type or it doesn't work... Content-type: text/html Content-language: en URI: index.it.html Content-type: text/html Content-language: it
This is bench.var :
URI: bench; vary="type" URI: bench.jpg Content-type: image/jpeg; qs=0.8 level=3 URI: bench.gif Content-type: image/gif; qs=0.5 level=1
The first line tells Apache what file is in question, here index.* or bench.* ; vary tells Apache what sort of variation we have. The possibilities are:
The name of the corresponding header, as defined in the HTTP specification, is obtained by prefixing these names with Content-. The headers are:
The qs numbers are quality scores , from to 1. You decide what they are and write them in. The qs values for each type of return are multiplied to give the overall qs for each variant. For instance, if a variant has a qs of .5 for Content-type and a qs of .7 for Content-language, its overall qs is .35. The higher the result, the better. The level values are also numbers, and you decide what they are. In order for Apache to decide rationally which possibility to return, it resolves ties in the following way:
If you can predict the outcome of all this in your head, you must qualify for some pretty classy award! Following is the full list of possible directives, given in the Apache documentation:
To throw this into action, start Apache with ./go, set the language of your browser to Italian, (in Netscape, choose Edit→Preferences→Netscape→Languages) and access http://www.butterthlies.com /. You should see the Italian version.
Copyright © 2001 O'Reilly & Associates. All rights reserved.