dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd<!-- $LastChangedRevision$ -->
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding Licensed to the Apache Software Foundation (ASF) under one or more
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding contributor license agreements. See the NOTICE file distributed with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding this work for additional information regarding copyright ownership.
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding The ASF licenses this file to You under the Apache License, Version 2.0
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding (the "License"); you may not use this file except in compliance with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding the License. You may obtain a copy of the License at
acc36ab93565d2880447d535da6ca6e5feac7a70nd Unless required by applicable law or agreed to in writing, software
acc36ab93565d2880447d535da6ca6e5feac7a70nd distributed under the License is distributed on an "AS IS" BASIS,
acc36ab93565d2880447d535da6ca6e5feac7a70nd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
acc36ab93565d2880447d535da6ca6e5feac7a70nd See the License for the specific language governing permissions and
acc36ab93565d2880447d535da6ca6e5feac7a70nd limitations under the License.
c68aa7f213d409d464eaa6b963afb28678548f4frbowen <p>Apache HTTPD supports content negotiation as described in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive representation of a resource based on the browser-supplied
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive preferences for media type, languages, character set and
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive encoding. It also implements a couple of features to give
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive more intelligent handling of requests from browsers that send
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive incomplete negotiation information.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>Content negotiation is provided by the
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl <module>mod_negotiation</module> module, which is compiled in
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl by default.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="about"><title>About Content Negotiation</title>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>A resource may be available in several different
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive representations. For example, it might be available in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive different languages or different media types, or a combination.
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive One way of selecting the most appropriate choice is to give the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive user an index page, and let them select. However it is often
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive possible for the server to choose automatically. This works
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl because browsers can send, as part of each request, information
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive about what representations they prefer. For example, a browser
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive could indicate that it would like to see information in French,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive if possible, else English will do. Browsers indicate their
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive preferences by headers in the request. To request only French
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive representations, the browser would send</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>Note that this preference will only be applied when there is
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive a choice of representations and they vary by language.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>As an example of a more complex request, this browser has
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive been configured to accept French and English, but prefer
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive French, and to accept various media types, preferring HTML over
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive plain text or other text types, and preferring GIF or JPEG over
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive other media types, but also allowing any other media type as a
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive last resort:</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Accept-Language: fr; q=1.0, en; q=0.5<br />
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen <p>httpd supports 'server driven' content negotiation, as
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive defined in the HTTP/1.1 specification. It fully supports the
ade10ab05a662b1297dc274b36666e292c8a9570humbedooh <code>Accept-Charset</code> and <code>Accept-Encoding</code>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen request headers. httpd also supports 'transparent'
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive content negotiation, which is an experimental negotiation
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive protocol defined in RFC 2295 and RFC 2296. It does not offer
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl support for 'feature negotiation' as defined in these RFCs.</p>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen identified by a URI (RFC 2396). An HTTP server like Apache HTTP Server
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive provides access to <strong>representations</strong> of the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive resource(s) within its namespace, with each representation in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the form of a sequence of bytes with a defined media type,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive character set, encoding, etc. Each resource may be associated
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive with zero, one, or more than one representation at any given
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive time. If multiple representations are available, the resource
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive is referred to as <strong>negotiable</strong> and each of its
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive representations is termed a <strong>variant</strong>. The ways
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive in which the variants for a negotiable resource vary are called
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen<section id="negotiation"><title>Negotiation in httpd</title>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>In order to negotiate a resource, the server needs to be
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive given information about each of the variants. This is done in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive one of two ways:</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Using a type map (<em>i.e.</em>, a <code>*.var</code>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive file) which names the files containing the variants
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive explicitly, or</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Using a 'MultiViews' search, where the server does an
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive implicit filename pattern match and chooses from among the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive results.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <section id="type-map"><title>Using a type-map file</title>
c14037646789087319802aaada2e8534ccab0158slive <p>A type map is a document which is associated with the handler
c14037646789087319802aaada2e8534ccab0158slive named <code>type-map</code> (or, for backwards-compatibility with
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen older httpd configurations, the <glossary>MIME-type</glossary>
c14037646789087319802aaada2e8534ccab0158slive <code>application/x-type-map</code>). Note that to use this
c14037646789087319802aaada2e8534ccab0158slive feature, you must have a handler set in the configuration that
c14037646789087319802aaada2e8534ccab0158slive defines a file suffix as <code>type-map</code>; this is best done
7a98571671f92e53441bf24a0222768072172f90coarAddHandler type-map .var
7a98571671f92e53441bf24a0222768072172f90coar </highlight>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>Type map files should have the same name as the resource
4766066659f83f25bad633f172e6315da8b850a3rbowen which they are describing, followed by the extension
4766066659f83f25bad633f172e6315da8b850a3rbowen <code>.var</code>. In the examples shown below, the resource is
4766066659f83f25bad633f172e6315da8b850a3rbowen named <code>foo</code>, so the type map file is named
4766066659f83f25bad633f172e6315da8b850a3rbowen <p>This file should have an entry for each available
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variant; these entries consist of contiguous HTTP-format header
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive lines. Entries for different variants are separated by blank
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive lines. Blank lines are illegal within an entry. It is
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive conventional to begin a map file with an entry for the combined
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive entity as a whole (although this is not required, and if
4766066659f83f25bad633f172e6315da8b850a3rbowen present will be ignored). An example map file is shown below.</p>
4766066659f83f25bad633f172e6315da8b850a3rbowen <p>URIs in this file are relative to the location of the type map
4766066659f83f25bad633f172e6315da8b850a3rbowen file. Usually, these files will be located in the same directory as
4766066659f83f25bad633f172e6315da8b850a3rbowen the type map file, but this is not required. You may provide
4766066659f83f25bad633f172e6315da8b850a3rbowen absolute or relative URIs for any file located on the same server as
4766066659f83f25bad633f172e6315da8b850a3rbowen the map file.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive URI: foo<br />
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Content-language: en<br />
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Content-language: fr, de<br />
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>Note also that a typemap file will take precedence over the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive filename's extension, even when Multiviews is on. If the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variants have different source qualities, that may be indicated
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive by the "qs" parameter to the media type, as in this picture
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl (available as JPEG, GIF, or ASCII-art): </p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive URI: foo<br />
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>qs values can vary in the range 0.000 to 1.000. Note that
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive any variant with a qs value of 0.000 will never be chosen.
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Variants with no 'qs' parameter value are given a qs factor of
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive 1.0. The qs parameter indicates the relative 'quality' of this
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variant compared to the other available variants, independent
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl of the client's capabilities. For example, a JPEG file is
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl usually of higher source quality than an ASCII file if it is
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive attempting to represent a photograph. However, if the resource
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl being represented is an original ASCII art, then an ASCII
2684d5de7d8996ac96df3a37e8f8a49c502f26dfjsl representation would have a higher source quality than a JPEG
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive representation. A qs value is therefore specific to a given
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variant depending on the nature of the resource it
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive represents.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>The full list of headers recognized is available in the <a
b76a31daaa6e83bb0fd627a04f20e82bffcf1df4poirier href="mod/mod_negotiation.html#typemaps">mod_negotiation
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p><code>MultiViews</code> is a per-directory option, meaning it
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive can be set with an <directive module="core">Options</directive>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive type="section">Directory</directive>, <directive module="core"
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive type="section">Location</directive> or <directive module="core"
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive module="core">AllowOverride</directive> is properly set) in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <code>.htaccess</code> files. Note that <code>Options All</code>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive does not set <code>MultiViews</code>; you have to ask for it by
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>The effect of <code>MultiViews</code> is as follows: if the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive server receives a request for <code>/some/dir/foo</code>, if
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <code>/some/dir</code> has <code>MultiViews</code> enabled, and
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <code>/some/dir/foo</code> does <em>not</em> exist, then the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive server reads the directory looking for files named foo.*, and
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive effectively fakes up a type map which names all those files,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive assigning them the same media types and content-encodings it
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive would have if the client had asked for one of them by name. It
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive then chooses the best match to the client's requirements.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p><code>MultiViews</code> may also apply to searches for the file
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive named by the <directive
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive module="mod_dir">DirectoryIndex</directive> directive, if the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive server is trying to index a directory. If the configuration files
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive specify</p>
7a98571671f92e53441bf24a0222768072172f90coarDirectoryIndex index
7a98571671f92e53441bf24a0222768072172f90coar </highlight>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>then the server will arbitrate between <code>index.html</code>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive and <code>index.html3</code> if both are present. If neither
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive are present, and <code>index.cgi</code> is there, the server
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive will run it.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>If one of the files found when reading the directory does not
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive have an extension recognized by <code>mod_mime</code> to designate
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive its Charset, Content-Type, Language, or Encoding, then the result
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive depends on the setting of the <directive
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive module="mod_mime">MultiViewsMatch</directive> directive. This
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive directive determines whether handlers, filters, and other
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive extension types can participate in MultiViews negotiation.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="methods"><title>The Negotiation Methods</title>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen <p>After httpd has obtained a list of the variants for a given
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive resource, either from a type-map file or from the filenames in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the directory, it invokes one of two methods to decide on the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive 'best' variant to return, if any. It is not necessary to know
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive any of the details of how negotiation actually takes place in
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen order to use httpd's content negotiation features. However the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive rest of this document explains the methods used for those
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive interested. </p>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen algorithm</strong> is used in the normal case. The httpd
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive algorithm is explained in more detail below. When this
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen algorithm is used, httpd can sometimes 'fiddle' the quality
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive factor of a particular dimension to achieve a better result.
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen The ways httpd can fiddle quality factors is explained in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive more detail below.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li><strong>Transparent content negotiation</strong> is used
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive when the browser specifically requests this through the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive mechanism defined in RFC 2295. This negotiation method gives
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the browser full control over deciding on the 'best' variant,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the result is therefore dependent on the specific algorithms
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive used by the browser. As part of the transparent negotiation
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen process, the browser can ask httpd to run the 'remote
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variant selection algorithm' defined in RFC 2296.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="dimensions"><title>Dimensions of Negotiation</title>
3209c0009829fcf63b6213fb9c43d534f7906006slive <columnspec><column width=".15"/><column width=".85"/></columnspec>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <td>Browser indicates preferences with the <code>Accept</code>
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl header field. Each item can have an associated quality factor.
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl Variant description can also have a quality factor (the "qs"
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl parameter).</td>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <td>Browser indicates preferences with the
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl <code>Accept-Language</code> header field. Each item can have
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl a quality factor. Variants can be associated with none, one or
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl more than one language.</td>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <td>Browser indicates preference with the
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl <code>Accept-Encoding</code> header field. Each item can have
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl a quality factor.</td>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <td>Browser indicates preference with the
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl <code>Accept-Charset</code> header field. Each item can have a
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl quality factor. Variants can indicate a charset as a parameter
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl of the media type.</td>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen<section id="algorithm"><title>httpd Negotiation Algorithm</title>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen <p>httpd can use the following algorithm to select the 'best'
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variant (if any) to return to the browser. This algorithm is
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive not further configurable. It operates as follows:</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>First, for each dimension of the negotiation, check the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive appropriate <em>Accept*</em> header field and assign a
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive quality to each variant. If the <em>Accept*</em> header for
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive any dimension implies that this variant is not acceptable,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive eliminate it. If no variants remain, go to step 4.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Select the 'best' variant by a process of elimination. Each
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive of the following tests is applied in order. Any variants
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive not selected at each test are eliminated. After each test,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive if only one variant remains, select it as the best match
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive and proceed to step 3. If more than one variant remains,
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim move on to the next test.
70fce89e67f707c03f70d437a64e189a205ffc35jsl <li>Multiply the quality factor from the <code>Accept</code>
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl header with the quality-of-source factor for this variants
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl media type, and select the variants with the highest
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl value.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select the variants with the highest language quality
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive factor.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select the variants with the best language match,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive using either the order of languages in the
70fce89e67f707c03f70d437a64e189a205ffc35jsl <code>Accept-Language</code> header (if present), or else
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl the order of languages in the <code>LanguagePriority</code>
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl directive (if present).</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select the variants with the highest 'level' media
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive parameter (used to give the version of text/html media
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive types).</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select variants with the best charset media
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl header line. Charset ISO-8859-1 is acceptable unless
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl explicitly excluded. Variants with a <code>text/*</code>
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl media type but not explicitly associated with a particular
f92d094f13138be62bcc1a4b8187d72705d2cb05jsl charset are assumed to be in ISO-8859-1.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select those variants which have associated charset
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive there are no such variants, select all variants
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive instead.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select the variants with the best encoding. If there
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive are variants with an encoding that is acceptable to the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive user-agent, select only these variants. Otherwise if
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive there is a mix of encoded and non-encoded variants,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive select only the unencoded variants. If either all
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive variants are encoded or all variants are not encoded,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive select all variants.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select the variants with the smallest content
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive length.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>Select the first variant of those remaining. This
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive will be either the first listed in the type-map file, or
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive when variants are read from the directory, the one whose
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive file name comes first when sorted using ASCII code
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive order.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>The algorithm has now selected one 'best' variant, so
70fce89e67f707c03f70d437a64e189a205ffc35jsl return it as the response. The HTTP response header
70fce89e67f707c03f70d437a64e189a205ffc35jsl negotiation (browsers and caches can use this information when
70fce89e67f707c03f70d437a64e189a205ffc35jsl caching the resource). End.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <li>To get here means no variant was selected (because none
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive are acceptable to the browser). Return a 406 status (meaning
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive "No acceptable representation") with a response body
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive consisting of an HTML document listing the available
70fce89e67f707c03f70d437a64e189a205ffc35jsl indicate the dimensions of variance.</li>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Values</title>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen <p>httpd sometimes changes the quality values from what would
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen be expected by a strict interpretation of the httpd
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive negotiation algorithm above. This is to get a better result
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive from the algorithm for browsers which do not send full or
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive accurate information. Some of the most popular browsers send
70fce89e67f707c03f70d437a64e189a205ffc35jsl <code>Accept</code> header information which would otherwise
70fce89e67f707c03f70d437a64e189a205ffc35jsl result in the selection of the wrong variant in many cases. If a
70fce89e67f707c03f70d437a64e189a205ffc35jsl browser sends full and correct information these fiddles will not
70fce89e67f707c03f70d437a64e189a205ffc35jsl be applied.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="wildcards"><title>Media Types and Wildcards</title>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <p>The <code>Accept:</code> request header indicates preferences
70fce89e67f707c03f70d437a64e189a205ffc35jsl for media types. It can also include 'wildcard' media types, such
70fce89e67f707c03f70d437a64e189a205ffc35jsl as "image/*" or "*/*" where the * matches any string. So a request
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive including:</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>would indicate that any type starting "image/" is acceptable,
e2108029921973b4522af1fe5ecd634a2a55ae07slive as is any other type.
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Some browsers routinely send wildcards in addition to explicit
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive types they can handle. For example:</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Accept: text/html, text/plain, image/gif, image/jpeg, */*
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>The intention of this is to indicate that the explicitly listed
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive types are preferred, but if a different representation is
e2108029921973b4522af1fe5ecd634a2a55ae07slive available, that is ok too. Using explicit quality values,
e2108029921973b4522af1fe5ecd634a2a55ae07slive what the browser really wants is something like:</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Accept: text/html, text/plain, image/gif, image/jpeg, */*; q=0.01
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>The explicit types have no quality factor, so they default to a
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive preference of 1.0 (the highest). The wildcard */* is given a
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive low preference of 0.01, so other types will only be returned if
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive no variant matches an explicitly listed type.</p>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <p>If the <code>Accept:</code> header contains <em>no</em> q
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen factors at all, httpd sets the q value of "*/*", if present, to
70fce89e67f707c03f70d437a64e189a205ffc35jsl 0.01 to emulate the desired behavior. It also sets the q value of
70fce89e67f707c03f70d437a64e189a205ffc35jsl wildcards of the format "type/*" to 0.02 (so these are preferred
70fce89e67f707c03f70d437a64e189a205ffc35jsl over matches against "*/*". If any media type on the
70fce89e67f707c03f70d437a64e189a205ffc35jsl <code>Accept:</code> header contains a q factor, these special
70fce89e67f707c03f70d437a64e189a205ffc35jsl values are <em>not</em> applied, so requests from browsers which
70fce89e67f707c03f70d437a64e189a205ffc35jsl send the explicit information to start with work as expected.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="exceptions"><title>Language Negotiation Exceptions</title>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen <p>New in httpd 2.0, some exceptions have been added to the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive negotiation algorithm to allow graceful fallback when language
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive negotiation fails to find a match.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>When a client requests a page on your server, but the server
70fce89e67f707c03f70d437a64e189a205ffc35jsl cannot find a single page that matches the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the browser, the server will return either a "No Acceptable
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Variant" or "Multiple Choices" response to the client. To avoid
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen these error messages, it is possible to configure httpd to ignore
70fce89e67f707c03f70d437a64e189a205ffc35jsl the <code>Accept-language</code> in these cases and provide a
70fce89e67f707c03f70d437a64e189a205ffc35jsl document that does not explicitly match the client's request. The
70fce89e67f707c03f70d437a64e189a205ffc35jsl <directive
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive module="mod_negotiation">ForceLanguagePriority</directive>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive directive can be used to override one or both of these error
70fce89e67f707c03f70d437a64e189a205ffc35jsl messages and substitute the servers judgement in the form of the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <directive module="mod_negotiation">LanguagePriority</directive>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive directive.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>The server will also attempt to match language-subsets when no
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive other match can be found. For example, if a client requests
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive documents with the language <code>en-GB</code> for British
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive English, the server is not normally allowed by the HTTP/1.1
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive standard to match that against a document that is marked as simply
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <code>en</code>. (Note that it is almost surely a configuration
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive error to include <code>en-GB</code> and not <code>en</code> in the
70fce89e67f707c03f70d437a64e189a205ffc35jsl <code>Accept-Language</code> header, since it is very unlikely
70fce89e67f707c03f70d437a64e189a205ffc35jsl that a reader understands British English, but doesn't understand
70fce89e67f707c03f70d437a64e189a205ffc35jsl English in general. Unfortunately, many current clients have
70fce89e67f707c03f70d437a64e189a205ffc35jsl default configurations that resemble this.) However, if no other
70fce89e67f707c03f70d437a64e189a205ffc35jsl language match is possible and the server is about to return a "No
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive Acceptable Variants" error or fallback to the <directive
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive module="mod_negotiation">LanguagePriority</directive>, the server
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive will ignore the subset specification and match <code>en-GB</code>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen against <code>en</code> documents. Implicitly, httpd will add
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the parent language to the client's acceptable language list with
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive a very low quality value. But note that if the client requests
e6b1bd85e7da3cac168dfef875298c55829c7ce1nd "en-GB; q=0.9, fr; q=0.8", and the server has documents
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive designated "en" and "fr", then the "fr" document will be returned.
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive This is necessary to maintain compliance with the HTTP/1.1
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive specification and to work effectively with properly configured
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive clients.</p>
70fce89e67f707c03f70d437a64e189a205ffc35jsl <p>In order to support advanced techniques (such as cookies or
5d81a8bafa2703e966db5bfd5abb33b176d47589nd special URL-paths) to determine the user's preferred language,
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen since httpd 2.0.47 <module>mod_negotiation</module> recognizes
5d81a8bafa2703e966db5bfd5abb33b176d47589nd <code>prefer-language</code>. If it exists and contains an
5d81a8bafa2703e966db5bfd5abb33b176d47589nd appropriate language tag, <module>mod_negotiation</module> will
5d81a8bafa2703e966db5bfd5abb33b176d47589nd try to select a matching variant. If there's no such variant,
5d81a8bafa2703e966db5bfd5abb33b176d47589nd the normal negotiation process applies.</p>
25bc0cc439abc002c56f746a04ae3d6ed15fbd7ehumbedoohSetEnvIf Cookie "language=(.+)" prefer-language=$1
25bc0cc439abc002c56f746a04ae3d6ed15fbd7ehumbedoohHeader append Vary cookie
25bc0cc439abc002c56f746a04ae3d6ed15fbd7ehumbedooh </highlight>
5d81a8bafa2703e966db5bfd5abb33b176d47589nd </example>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="extensions"><title>Extensions to Transparent Content
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimNegotiation</title>
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen<p>httpd extends the transparent content negotiation protocol (RFC
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive2295) as follows. A new <code>{encoding ..}</code> element is used in
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slivevariant lists to label variants which are available with a specific
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slivecontent-encoding only. The implementation of the RVSA/1.0 algorithm
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive(RFC 2296) is extended to recognize encoded variants in the list, and
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16sliveto use them as candidate variants whenever their encodings are
70fce89e67f707c03f70d437a64e189a205ffc35jslacceptable according to the <code>Accept-Encoding</code> request
70fce89e67f707c03f70d437a64e189a205ffc35jslheader. The RVSA/1.0 implementation does not round computed quality
70fce89e67f707c03f70d437a64e189a205ffc35jslfactors to 5 decimal places before choosing the best variant.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive<section id="naming"><title>Note on hyperlinks and naming conventions</title>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>If you are using language negotiation you can choose between
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive different naming conventions, because files can have more than
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive one extension, and the order of the extensions is normally
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive irrelevant (see the <a
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive href="mod/mod_mime.html#multipleext">mod_mime</a> documentation
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive for details).</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>A typical file has a MIME-type extension (<em>e.g.</em>,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <code>html</code>), maybe an encoding extension (<em>e.g.</em>,
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive (<em>e.g.</em>, <code>en</code>) when we have different
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive language variants of this file.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>Here some more examples of filenames together with valid and
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive invalid hyperlinks:</p>
7a1e9d49b574baedc5d9a6f384308039745332d9pepper <p>Looking at the table above, you will notice that it is always
7a1e9d49b574baedc5d9a6f384308039745332d9pepper possible to use the name without any extensions in a hyperlink
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive (<em>e.g.</em>, <code>foo</code>). The advantage is that you
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive can hide the actual type of a document rsp. file and can change
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <code>shtml</code> or <code>cgi</code> without changing any
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive hyperlink references.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>If you want to continue to use a MIME-type in your
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive hyperlinks (<em>e.g.</em> <code>foo.html</code>) the language
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive extension (including an encoding extension if there is one)
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive must be on the right hand side of the MIME-type extension
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>When a cache stores a representation, it associates it with
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive the request URL. The next time that URL is requested, the cache
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive can use the stored representation. But, if the resource is
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive negotiable at the server, this might result in only the first
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive requested variant being cached and subsequent cache hits might
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen return the wrong response. To prevent this, httpd normally
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive marks all responses that are returned after content negotiation
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen as non-cacheable by HTTP/1.0 clients. httpd also supports the
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive HTTP/1.1 protocol features to allow caching of negotiated
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive responses.</p>
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive <p>For requests which come from a HTTP/1.0 compliant client
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive (either a browser or a cache), the directive <directive
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive module="mod_negotiation">CacheNegotiatedDocs</directive> can be
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive used to allow caching of responses which were subject to
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive negotiation. This directive can be given in the server config or
dd9f0e560e29dc86fba5f5d4fa5e72cda5cefb16slive virtual host, and takes no arguments. It has no effect on requests
cfebc848e619d381e71d40b6f489db4aac180ee5rbowen <p>For HTTP/1.1 clients, httpd sends a <code>Vary</code> HTTP
221e8a19d2201546e7efe590924383c2a7f0fd72slive response header to indicate the negotiation dimensions for the
221e8a19d2201546e7efe590924383c2a7f0fd72slive response. Caches can use this information to determine whether a
221e8a19d2201546e7efe590924383c2a7f0fd72slive subsequent request can be served from the local copy. To
221e8a19d2201546e7efe590924383c2a7f0fd72slive encourage a cache to use the local copy regardless of the
221e8a19d2201546e7efe590924383c2a7f0fd72slive negotiation dimensions, set the <code>force-no-vary</code> <a
7a1e9d49b574baedc5d9a6f384308039745332d9pepper</manualpage>