Apache content negotiation Filed Under: Apache
Introduction
As a website may have available its resources in various languages. The server will provide the appropriate language version of the resource by listening the specification of the web browser. For example to request a web page in Spanish the web browser will send the following command:
Accept-language: es
If the web browser doesn’t specify any language preference the server will provide a default one. In the case that you provide a language that the server cannot provide, the server will return “error 406 Not acceptable” and will provide a list of the available variants.
Apache in order to know which variant to use needs to receive the appropriate information. This can be done in two different ways:
- Using type maps: This are files files with the extension .var. This files contains a list of the variants
- Using Multiviews: In this case the server searches for a specific pattern of the filename and provide the variant depending of the results of the search.
Type maps
To use type map documents we need to first associate the type map documents with a handler type-map.
AddHandler type-map .var
This handler will define the suffix .var as a type-map file.
Type map files contain the entities for each different variant. This entities are separated by blank lines and are illegal within an entry. This map files are located in the same directory as the various variants of the resource
For example a file foo.var place in the same directory with the different variants of a file foo will contain:
URI: foo.html.en
Content-type: text/html
Content-language: en
URI: foo.html.es
Content-type: text/html
Content-language: es
Multiviews
Multiviews is a per-directory option meaning that can be set with the Options
directive within the configuration file httpd.conf
, access.conf
or .htaccess
if the property is set.
The way Multiviews work is: if the page /some/page/file is requested to the server and the directory /some/page has Multiviews enabled the server will look for the file /some/page/file, if that file does not exits then the server does a search on the directory /some/page for files named file.* and fakes a virtual map with all the files found and thus providing the best match to the client.
Naming conventions
In language negotiation you can choose between various naming conventions. Filenames can have more than one extension and the order is normally irrelevant, is just relevant in the case you provide hyperlinks in your website. The following table shows some examples of different filenames with valid and invalid extensions.
Filename | Valid Hyperlink | Invalid Hyperlink |
page.html.es | page page.html |
none |
page | page | page.html |
page.es.html | page page.html |
none |
References
Apache official documentation about content-negotiation
Tutorial about var type content negotiation
RFC1766 – RFC for Identification of languages
- Permalink
- Alberto Diaz
- 16 Dec 2006 6:56 PM
- Comments (0)