content-negotiation.html revision b898ccd2b9aad43056f06f89badc75b3b60ebb40
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<HTML>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<HEAD>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<TITLE>Apache Content Negotiation</TITLE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</HEAD>
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<BODY
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes BGCOLOR="#FFFFFF"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes TEXT="#000000"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes LINK="#0000FF"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes VLINK="#000080"
0662ed52e814f8f08ef0e09956413a792584eddffuankg ALINK="#FF0000"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<!--#include virtual="header.html" -->
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<H1 ALIGN="CENTER">Content Negotiation</H1>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesApache's support for content negotiation has been updated to meet the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesHTTP/1.1 specification. It can choose the best representation of a
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesresource based on the browser-supplied preferences for media type,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholeslanguages, character set and encoding. It is also implements a
bb2b38cd44b032118359afbc743efbea12f48e61bnicholescouple of features to give more intelligent handling of requests from
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesbrowsers which send incomplete negotiation information. <P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholesContent negotiation is provided by the
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes<A HREF="mod/mod_negotiation.html">mod_negotiation</A> module,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholeswhich is compiled in by default.
cfb941e9ad5276eef7bc8f3eedcd270f30cfec35fuankg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<HR>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<H2>About Content Negotiation</H2>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesA resource may be available in several different representations. For
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesexample, it might be available in different languages or different
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesmedia types, or a combination. One way of selecting the most
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesappropriate choice is to give the user an index page, and let them
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesselect. However it is often possible for the server to choose
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesautomatically. This works because browsers can send as part of each
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesrequest information about what representations they prefer. For
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesexample, a browser could indicate that it would like to see
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesinformation in French, if possible, else English will do. Browsers
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesindicate their preferences by headers in the request. To request only
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesFrench representations, the browser would send
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Accept-Language: fr
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesNote that this preference will only be applied when there is a choice
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesof representations and they vary by language.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAs an example of a more complex request, this browser has been
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesconfigured to accept French and English, but prefer French, and to
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesaccept various media types, preferring HTML over plain text or other
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestext types, and preferring GIF or JPEG over other media types, but also
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesallowing any other media type as a last resort:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Accept-Language: fr; q=1.0, en; q=0.5
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg</PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesApache 1.2 supports 'server driven' content negotiation, as defined in
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesthe HTTP/1.1 specification. It fully supports the Accept,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAccept-Language, Accept-Charset and Accept-Encoding request headers.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesApache 1.3.4 also supports 'transparent' content negotiation, which is
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesan experimental negotiation protocol defined in RFC 2295 and RFC 2296.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesIt does not offer support for 'feature negotiation' as defined in
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesthese RFCs.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesA <STRONG>resource</STRONG> is a conceptual entity identified by a URI
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes(RFC 2396). An HTTP server like Apache provides access to
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<STRONG>representations</STRONG> of the resource(s) within its namespace,
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgwith each representation in the form of a sequence of bytes with a
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesdefined media type, character set, encoding, etc. Each resource may be
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesassociated with zero, one, or more than one representation
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesat any given time. If multiple representations are available,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesthe resource is referred to as <STRONG>negotiable</STRONG> and each of its
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesrepresentations is termed a <STRONG>variant</STRONG>. The ways in which the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesvariants for a negotiable resource vary are called the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<STRONG>dimensions</STRONG> of negotiation.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<H2>Negotiation in Apache</H2>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesIn order to negotiate a resource, the server needs to be given
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesinformation about each of the variants. This is done in one of two
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesways:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<UL>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <LI> Using a type map (<EM>i.e.</EM>, a <CODE>*.var</CODE> file) which
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes names the files containing the variants explicitly, or
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <LI> Using a 'MultiViews' search, where the server does an implicit
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes filename pattern match and chooses from among the results.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</UL>
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<H3>Using a type-map file</H3>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesA type map is a document which is associated with the handler
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesnamed <CODE>type-map</CODE> (or, for backwards-compatibility with
0a39e7683f6611d66c55712f50bb240428d832a1bnicholesolder Apache configurations, the mime type
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>application/x-type-map</CODE>). Note that to use this feature,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesyou must have a handler set in the configuration that defines a
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesfile suffix as <CODE>type-map</CODE>; this is best done with a
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes AddHandler type-map .var
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgin the server configuration file. See the comments in the sample config
0662ed52e814f8f08ef0e09956413a792584eddffuankgfile for more details. <P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgType map files have an entry for each available variant; these entries
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesconsist of contiguous HTTP-format header lines. Entries for
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesdifferent variants are separated by blank lines. Blank lines are
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesillegal within an entry. It is conventional to begin a map file with
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesan entry for the combined entity as a whole (although this
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesis not required, and if present will be ignored). An example
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgmap file is:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes URI: foo
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
0662ed52e814f8f08ef0e09956413a792584eddffuankg URI: foo.en.html
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Content-type: text/html
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Content-language: en
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes URI: foo.fr.de.html
0662ed52e814f8f08ef0e09956413a792584eddffuankg Content-type: text/html;charset=iso-8859-2
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Content-language: fr, de
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesIf the variants have different source qualities, that may be indicated
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesby the "qs" parameter to the media type, as in this picture (available
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesas jpeg, gif, or ASCII-art):
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes URI: foo
0662ed52e814f8f08ef0e09956413a792584eddffuankg
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg URI: foo.jpeg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Content-type: image/jpeg; qs=0.8
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes URI: foo.gif
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Content-type: image/gif; qs=0.5
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg URI: foo.txt
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Content-type: text/plain; qs=0.01
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesqs values can vary in the range 0.000 to 1.000. Note that any variant with
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesa qs value of 0.000 will never be chosen. Variants with no 'qs'
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesparameter value are given a qs factor of 1.0. The qs parameter indicates
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesthe relative 'quality' of this variant compared to the other available
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesvariants, independent of the client's capabilities. For example, a jpeg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesfile is usually of higher source quality than an ascii file if it is
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesattempting to represent a photograph. However, if the resource being
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesrepresented is an original ascii art, then an ascii representation would
bb2b38cd44b032118359afbc743efbea12f48e61bnicholeshave a higher source quality than a jpeg representation. A qs value
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesis therefore specific to a given variant depending on the nature of
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesthe resource it represents.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesThe full list of headers recognized is:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<DL>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DT> <CODE>URI:</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DD> uri of the file containing the variant (of the given media
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes type, encoded with the given content encoding). These are
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes interpreted as URLs relative to the map file; they must be on
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes the same server (!), and they must refer to files to which the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes client would be granted access if they were to be requested
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes directly.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DT> <CODE>Content-Type:</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DD> media type --- charset, level and "qs" parameters may be given. These
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes are often referred to as MIME types; typical media types are
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <CODE>image/gif</CODE>, <CODE>text/plain</CODE>, or
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <CODE>text/html;&nbsp;level=3</CODE>.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DT> <CODE>Content-Language:</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DD> The languages of the variant, specified as an Internet standard
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes language tag from RFC 1766 (<EM>e.g.</EM>, <CODE>en</CODE> for English,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <CODE>kr</CODE> for Korean, <EM>etc.</EM>).
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DT> <CODE>Content-Encoding:</CODE>
cf7ca2f9eaa6523fefcccba4287b91637391fb51fuankg <DD> If the file is compressed, or otherwise encoded, rather than
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes containing the actual raw data, this says how that was done.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Apache only recognizes encodings that are defined by an
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <A HREF="mod/mod_mime.html#addencoding">AddEncoding</A> directive.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes This normally includes the encodings <CODE>x-compress</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for compress'd files, and <CODE>x-gzip</CODE> for gzip'd files.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes The <CODE>x-</CODE> prefix is ignored for encoding comparisons.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DT> <CODE>Content-Length:</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DD> The size of the file. Specifying content
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes lengths in the type-map allows the server to compare file sizes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes without checking the actual files.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DT> <CODE>Description:</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes <DD> A human-readable textual description of the variant. If Apache cannot
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes find any appropriate variant to return, it will return an error
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes response which lists all available variants instead. Such a variant
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes list will include the human-readable variant descriptions.
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg</DL>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<H3>Multiviews</H3>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>MultiViews</CODE> is a per-directory option, meaning it can be set with
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesan <CODE>Options</CODE> directive within a <CODE>&lt;Directory&gt;</CODE>,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>&lt;Location&gt;</CODE> or <CODE>&lt;Files&gt;</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholessection in <CODE>access.conf</CODE>, or (if <CODE>AllowOverride</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesis properly set) in <CODE>.htaccess</CODE> files. Note that
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>Options All</CODE> does not set <CODE>MultiViews</CODE>; you
bb2b38cd44b032118359afbc743efbea12f48e61bnicholeshave to ask for it by name.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesThe effect of <CODE>MultiViews</CODE> is as follows: if the server
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesreceives a request for <CODE>/some/dir/foo</CODE>, if
8ffac2c334103c0336602aaede650cb578611151fuankg<CODE>/some/dir</CODE> has <CODE>MultiViews</CODE> enabled, and
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>/some/dir/foo</CODE> does <EM>not</EM> exist, then the server reads the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesdirectory looking for files named foo.*, and effectively fakes up a
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgtype map which names all those files, assigning them the same media
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgtypes and content-encodings it would have if the client had asked for
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesone of them by name. It then chooses the best match to the client's
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesrequirements.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>MultiViews</CODE> may also apply to searches for the file named by the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<CODE>DirectoryIndex</CODE> directive, if the server is trying to
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgindex a directory. If the configuration files specify
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DirectoryIndex index
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes</PRE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgthen the server will arbitrate between <CODE>index.html</CODE>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesand <CODE>index.html3</CODE> if both are present. If neither are
bb2b38cd44b032118359afbc743efbea12f48e61bnicholespresent, and <CODE>index.cgi</CODE> is there, the server will run it.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesIf one of the files found when reading the directive is a CGI script,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesit's not obvious what should happen. The code gives that case
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesspecial treatment --- if the request was a POST, or a GET with
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesQUERY_ARGS or PATH_INFO, the script is given an extremely high quality
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesrating, and generally invoked; otherwise it is given an extremely low
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesquality rating, which generally causes one of the other views (if any)
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgto be retrieved.
0662ed52e814f8f08ef0e09956413a792584eddffuankg
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<H2>The Negotiation Methods</H2>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
2a3d4464b68bcf6173f675479b4ec681a83f4bd9fuankgAfter Apache has obtained a list of the variants for a given resource,
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgeither from a type-map file or from the filenames in the directory, it
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesinvokes one of two methods to decide on the 'best' variant to
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesreturn, if any. It is not necessary to know any of the details of how
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesnegotiation actually takes place in order to use Apache's content
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesnegotiation features. However the rest of this document explains the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesmethods used for those interested.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<P>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesThere are two negotiation methods:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
0662ed52e814f8f08ef0e09956413a792584eddffuankg<OL>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes<LI><STRONG>Server driven negotiation with the Apache
algorithm</STRONG> is used in the normal case. The Apache algorithm is
explained in more detail below. When this algorithm is used, Apache
can sometimes 'fiddle' the quality factor of a particular dimension to
achieve a better result. The ways Apache can fiddle quality factors is
explained in more detail below.
<LI><STRONG>Transparent content negotiation</STRONG> is used when the
browser specifically requests this through the mechanism defined in RFC
2295. This negotiation method gives the browser full control over
deciding on the 'best' variant, the result is therefore dependent on
the specific algorithms used by the browser. As part of the
transparent negotiation process, the browser can ask Apache to run the
'remote variant selection algorithm' defined in RFC 2296.
</OL>
<H3>Dimensions of Negotiation</H3>
<TABLE>
<TR valign="top">
<TH>Dimension
<TH>Notes
<TR valign="top">
<TD>Media Type
<TD>Browser indicates preferences with the Accept header field. Each item
can have an associated quality factor. Variant description can also
have a quality factor (the "qs" parameter).
<TR valign="top">
<TD>Language
<TD>Browser indicates preferences with the Accept-Language header field.
Each item can have a quality factor. Variants can be associated with none, one
or more than one language.
<TR valign="top">
<TD>Encoding
<TD>Browser indicates preference with the Accept-Encoding header field.
Each item can have a quality factor.
<TR valign="top">
<TD>Charset
<TD>Browser indicates preference with the Accept-Charset header field.
Each item can have a quality factor.
Variants can indicate a charset as a parameter of the media type.
</TABLE>
<H3>Apache Negotiation Algorithm</H3>
<P>
Apache can use the following algorithm to select the 'best' variant
(if any) to return to the browser. This algorithm is not
further configurable. It operates as follows:
<OL>
<LI>First, for each dimension of the negotiation, check the appropriate
<EM>Accept*</EM> header field and assign a quality to each
variant. If the <EM>Accept*</EM> header for any dimension implies that this
variant is not acceptable, eliminate it. If no variants remain, go
to step 4.
<LI>Select the 'best' variant by a process of elimination. Each of the
following tests is applied in order. Any variants not selected at each
test are eliminated. After each test, if only one variant remains,
select it as the best match and proceed to step 3. If more than one
variant remains, move on to the next test.
<OL>
<LI>Multiply the quality factor from the Accept header with the
quality-of-source factor for this variant's media type, and select
the variants with the highest value.
<LI>Select the variants with the highest language quality factor.
<LI>Select the variants with the best language match, using either the
order of languages in the Accept-Language header (if present), or else
the order of languages in the <CODE>LanguagePriority</CODE>
directive (if present).
<LI>Select the variants with the highest 'level' media parameter
(used to give the version of text/html media types).
<LI>Select variants with the best charset media parameters,
as given on the Accept-Charset header line. Charset ISO-8859-1
is acceptable unless explicitly excluded. Variants with a
<CODE>text/*</CODE> media type but not explicitly associated
with a particular charset are assumed to be in ISO-8859-1.
<LI>Select those variants which have associated
charset media parameters that are <EM>not</EM> ISO-8859-1.
If there are no such variants, select all variants instead.
<LI>Select the variants with the best encoding. If there are
variants with an encoding that is acceptable to the user-agent,
select only these variants. Otherwise if there is a mix of encoded
and non-encoded variants, select only the unencoded variants.
If either all variants are encoded or all variants are not encoded,
select all variants.
<LI>Select the variants with the smallest content length.
<LI>Select the first variant of those remaining. This will be either the
first listed in the type-map file, or when variants are read from
the directory, the one whose file name comes first when sorted using
ASCII code order.
</OL>
<LI>The algorithm has now selected one 'best' variant, so return
it as the response. The HTTP response header Vary is set to indicate the
dimensions of negotiation (browsers and caches can use this
information when caching the resource). End.
<LI>To get here means no variant was selected (because none are acceptable
to the browser). Return a 406 status (meaning "No acceptable representation")
with a response body consisting of an HTML document listing the
available variants. Also set the HTTP Vary header to indicate the
dimensions of variance.
</OL>
<H2><A NAME="better">Fiddling with Quality Values</A></H2>
<P>
Apache sometimes changes the quality values from what would be
expected by a strict interpretation of the Apache negotiation
algorithm above. This is to get a better result from the algorithm for
browsers which do not send full or accurate information. Some of the
most popular browsers send Accept header information which would
otherwise result in the selection of the wrong variant in many
cases. If a browser sends full and correct information these fiddles
will not be applied.
<P>
<H3>Media Types and Wildcards</H3>
<P>
The Accept: request header indicates preferences for media types. It
can also include 'wildcard' media types, such as "image/*" or "*/*"
where the * matches any string. So a request including:
<PRE>
Accept: image/*, */*
</PRE>
would indicate that any type starting "image/" is acceptable,
as is any other type (so the first "image/*" is redundant). Some
browsers routinely send wildcards in addition to explicit types they
can handle. For example:
<PRE>
Accept: text/html, text/plain, image/gif, image/jpeg, */*
</PRE>
The intention of this is to indicate that the explicitly
listed types are preferred, but if a different representation is
available, that is ok too. However under the basic algorithm, as given
above, the */* wildcard has exactly equal preference to all the other
types, so they are not being preferred. The browser should really have
sent a request with a lower quality (preference) value for *.*, such
as:
<PRE>
Accept: text/html, text/plain, image/gif, image/jpeg, */*; q=0.01
</PRE>
The explicit types have no quality factor, so they default to a
preference of 1.0 (the highest). The wildcard */* is given
a low preference of 0.01, so other types will only be returned if
no variant matches an explicitly listed type.
<P>
If the Accept: header contains <EM>no</EM> q factors at all, Apache sets
the q value of "*/*", if present, to 0.01 to emulate the desired
behavior. It also sets the q value of wildcards of the format
"type/*" to 0.02 (so these are preferred over matches against
"*/*". If any media type on the Accept: header contains a q factor,
these special values are <EM>not</EM> applied, so requests from browsers
which send the correct information to start with work as expected.
<H3>Variants with no Language</H3>
<P>
If some of the variants for a particular resource have a language
attribute, and some do not, those variants with no language
are given a very low language quality factor of 0.001.<P>
The reason for setting this language quality factor for
variant with no language to a very low value is to allow
for a default variant which can be supplied if none of the
other variants match the browser's language preferences.
For example, consider the situation with three variants:
<UL>
<LI>foo.en.html, language en
<LI>foo.fr.html, language en
<LI>foo.html, no language
</UL>
<P>
The meaning of a variant with no language is that it is
always acceptable to the browser. If the request Accept-Language
header includes either en or fr (or both) one of foo.en.html
or foo.fr.html will be returned. If the browser does not list
either en or fr as acceptable, foo.html will be returned instead.
<H2>Extensions to Transparent Content Negotiation</H2>
Apache extends the transparent content negotiation protocol (RFC 2295)
as follows. A new <CODE> {encoding ..}</CODE> element is used in
variant lists to label variants which are available with a specific
content-encoding only. The implementation of the
RVSA/1.0 algorithm (RFC 2296) is extended to recognize encoded
variants in the list, and to use them as candidate variants whenever
their encodings are acceptable according to the Accept-Encoding
request header. The RVSA/1.0 implementation does not round computed
quality factors to 5 decimal places before choosing the best variant.
<H2>Note on hyperlinks and naming conventions</H2>
<P>
If you are using language negotiation you can choose between
different naming conventions, because files can have more than one
extension, and the order of the extensions is normally irrelevant
(see <A HREF="mod/mod_mime.html">mod_mime</A> documentation for details).
<P>
A typical file has a MIME-type extension (<EM>e.g.</EM>, <SAMP>html</SAMP>),
maybe an encoding extension (<EM>e.g.</EM>, <SAMP>gz</SAMP>), and of course a
language extension (<EM>e.g.</EM>, <SAMP>en</SAMP>) when we have different
language variants of this file.
<P>
Examples:
<UL>
<LI>foo.en.html
<LI>foo.html.en
<LI>foo.en.html.gz
</UL>
<P>
Here some more examples of filenames together with valid and invalid
hyperlinks:
</P>
<TABLE BORDER=1 CELLPADDING=8 CELLSPACING=0>
<TR>
<TH>Filename</TH>
<TH>Valid hyperlink</TH>
<TH>Invalid hyperlink</TH>
</TR>
<TR>
<TD><EM>foo.html.en</EM></TD>
<TD>foo<BR>
foo.html</TD>
<TD>-</TD>
</TR>
<TR>
<TD><EM>foo.en.html</EM></TD>
<TD>foo</TD>
<TD>foo.html</TD>
</TR>
<TR>
<TD><EM>foo.html.en.gz</EM></TD>
<TD>foo<BR>
foo.html</TD>
<TD>foo.gz<BR>
foo.html.gz</TD>
</TR>
<TR>
<TD><EM>foo.en.html.gz</EM></TD>
<TD>foo</TD>
<TD>foo.html<BR>
foo.html.gz<BR>
foo.gz</TD>
</TR>
<TR>
<TD><EM>foo.gz.html.en</EM></TD>
<TD>foo<BR>
foo.gz<BR>
foo.gz.html</TD>
<TD>foo.html</TD>
</TR>
<TR>
<TD><EM>foo.html.gz.en</EM></TD>
<TD>foo<BR>
foo.html<BR>
foo.html.gz</TD>
<TD>foo.gz</TD>
</TR>
</TABLE>
<P>
Looking at the table above you will notice that it is always possible to
use the name without any extensions in an hyperlink (<EM>e.g.</EM>, <SAMP>foo</SAMP>).
The advantage is that you can hide the actual type of a
document rsp. file and can change it later, <EM>e.g.</EM>, from <SAMP>html</SAMP>
to <SAMP>shtml</SAMP> or <SAMP>cgi</SAMP> without changing any
hyperlink references.
<P>
If you want to continue to use a MIME-type in your hyperlinks (<EM>e.g.</EM>
<SAMP>foo.html</SAMP>) the language extension (including an encoding extension
if there is one) must be on the right hand side of the MIME-type extension
(<EM>e.g.</EM>, <SAMP>foo.html.en</SAMP>).
<H2>Note on Caching</H2>
<P>
When a cache stores a representation, it associates it with the request URL.
The next time that URL is requested, the cache can use the stored
representation. But, if the resource is negotiable at the server,
this might result in only the first requested variant being cached and
subsequent cache hits might return the wrong response. To prevent this,
Apache normally marks all responses that are returned after content negotiation
as non-cacheable by HTTP/1.0 clients. Apache also supports the HTTP/1.1
protocol features to allow caching of negotiated responses. <P>
For requests which come from a HTTP/1.0 compliant client (either a
browser or a cache), the directive <TT>CacheNegotiatedDocs</TT> can be
used to allow caching of responses which were subject to negotiation.
This directive can be given in the server config or virtual host, and
takes no arguments. It has no effect on requests from HTTP/1.1 clients.
<!--#include virtual="footer.html" -->
</BODY>
</HTML>