2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
6 Copyright 2002-2004 Apache Software Foundation
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
21 <modulesynopsis metafile="mod_negotiation.xml.meta">
23 <name>mod_negotiation</name>
24 <description>Provides for <a
25 href="../content-negotiation.html">content negotiation</a></description>
27 <sourcefile>mod_negotiation.c</sourcefile>
28 <identifier>negotiation_module</identifier>
31 <p>Content negotiation, or more accurately content selection, is
32 the selection of the document that best matches the clients
33 capabilities, from one of several available documents. There
34 are two implementations of this.</p>
37 <li>A type map (a file with the handler
38 <code>type-map</code>) which explicitly lists the files
39 containing the variants.</li>
41 <li>A MultiViews search (enabled by the <code>MultiViews</code>
42 <directive module="core">Options</directive>), where the server does
43 an implicit filename pattern match, and choose from amongst the
47 <seealso><directive module="core">Options</directive></seealso>
48 <seealso><module>mod_mime</module></seealso>
49 <seealso><a href="../content-negotiation.html">Content
50 Negotiation</a></seealso>
51 <seealso><a href="../env.html">Environment Variables</a></seealso>
53 <section id="typemaps"><title>Type maps</title>
54 <p>A type map has a format similar to RFC822 mail headers. It
55 contains document descriptions separated by blank lines, with
56 lines beginning with a hash character ('#') treated as
57 comments. A document description consists of several header
58 records; records may be continued on multiple lines if the
59 continuation lines start with spaces. The leading space will be
60 deleted and the lines concatenated. A header record consists of
61 a keyword name, which always ends in a colon, followed by a
62 value. Whitespace is allowed between the header name and value,
63 and between the tokens of value. The headers allowed are: </p>
66 <dt><code>Content-Encoding:</code></dt>
67 <dd>The encoding of the file. Apache only recognizes
68 encodings that are defined by an <directive
69 module="mod_mime">AddEncoding</directive> directive.
70 This normally includes the encodings <code>x-compress</code>
71 for compress'd files, and <code>x-gzip</code> for gzip'd
72 files. The <code>x-</code> prefix is ignored for encoding
75 <dt><code>Content-Language:</code></dt>
76 <dd>The language(s) of the variant, as an Internet standard
77 language tag (<a href="http://www.ietf.org/rfc/rfc1766.txt"
78 >RFC 1766</a>). An example is <code>en</code>,
79 meaning English. If the variant contains more than one
80 language, they are separated by a comma.</dd>
82 <dt><code>Content-Length:</code></dt>
83 <dd>The length of the file, in bytes. If this header is not
84 present, then the actual length of the file is used.</dd>
86 <dt><code>Content-Type:</code></dt>
89 The MIME media type of the document, with optional
90 parameters. Parameters are separated from the media type
91 and from one another by a semi-colon, with a syntax of
92 <code>name=value</code>. Common parameters include:
95 <dt><code>level</code></dt>
96 <dd>an integer specifying the version of the media type.
97 For <code>text/html</code> this defaults to 2, otherwise
100 <dt><code>qs</code></dt>
101 <dd>a floating-point number with a value in the range 0.0
102 to 1.0, indicating the relative 'quality' of this variant
103 compared to the other available variants, independent of
104 the client's capabilities. For example, a jpeg file is
105 usually of higher source quality than an ascii file if it
106 is attempting to represent a photograph. However, if the
107 resource being represented is ascii art, then an ascii
108 file would have a higher source quality than a jpeg file.
109 All <code>qs</code> values are therefore specific to a given
113 <example><title>Example</title>
114 Content-Type: image/jpeg; qs=0.8
118 <dt><code>URI:</code></dt>
119 <dd>uri of the file containing the variant (of the given
120 media type, encoded with the given content encoding). These
121 are interpreted as URLs relative to the map file; they must
122 be on the same server (!), and they must refer to files to
123 which the client would be granted access if they were to be
124 requested directly.</dd>
126 <dt><code>Body:</code></dt>
127 <dd>New in Apache 2.0, the actual content of the resource may
128 be included in the type-map file using the Body header. This
129 header must contain a string that designates a delimiter for
130 the body content. Then all following lines in the type map
131 file will be considered part of the resource body until the
132 delimiter string is found.
134 <example><title>Example:</title>
135 Body:----xyz----<br />
138 <p>Content of the page.</p><br />
147 <section id="multiviews"><title>MultiViews</title>
148 <p>A MultiViews search is enabled by the <code>MultiViews</code>
149 <directive module="core">Options</directive>. If the server receives a
150 request for <code>/some/dir/foo</code> and
151 <code>/some/dir/foo</code> does <em>not</em> exist, then the
152 server reads the directory looking for all files named
153 <code>foo.*</code>, and effectively fakes up a type map which
154 names all those files, assigning them the same media types and
155 content-encodings it would have if the client had asked for one
156 of them by name. It then chooses the best match to the client's
157 requirements, and returns that document.</p>
159 <p>The <directive module="mod_mime">MultiViewsMatch</directive>
160 directive configures whether Apache will consider files
161 that do not have content negotiation meta-information assigned
162 to them when choosing files.</p>
166 <name>CacheNegotiatedDocs</name>
167 <description>Allows content-negotiated documents to be
168 cached by proxy servers</description>
169 <syntax>CacheNegotiatedDocs On|Off</syntax>
170 <default>CacheNegotiatedDocs Off</default>
171 <contextlist><context>server config</context><context>virtual host</context>
173 <compatibility>The syntax changed in version 2.0.</compatibility>
176 <p>If set, this directive allows content-negotiated documents
177 to be cached by proxy servers. This could mean that clients
178 behind those proxys could retrieve versions of the documents
179 that are not the best match for their abilities, but it will
180 make caching more efficient.</p>
182 <p>This directive only applies to requests which come from
183 HTTP/1.0 browsers. HTTP/1.1 provides much better control over
184 the caching of negotiated documents, and this directive has no
185 effect in responses to HTTP/1.1 requests.</p>
187 <p>Prior to version 2.0,
188 <directive>CacheNegotiatedDocs</directive> did not take an
189 argument; it was turned on by the presence of the directive by
195 <name>ForceLanguagePriority</name>
196 <description>Action to take if a single acceptable document is not
198 <syntax>ForceLanguagePriority None|Prefer|Fallback [Prefer|Fallback]</syntax>
199 <default>ForceLanguagePriority Prefer</default>
200 <contextlist><context>server config</context><context>virtual host</context>
201 <context>directory</context><context>.htaccess</context></contextlist>
202 <override>FileInfo</override>
203 <compatibility>Available in version 2.0.30 and later</compatibility>
206 <p>The <directive>ForceLanguagePriority</directive> directive uses
208 module="mod_negotiation">LanguagePriority</directive> to satisfy
209 negotation where the server could otherwise not return a single
210 matching document.</p>
212 <p><code>ForceLanguagePriority Prefer</code> uses
213 <code>LanguagePriority</code> to serve a one valid result, rather
214 than returning an HTTP result 300 (MULTIPLE CHOICES) when there
215 are several equally valid choices. If the directives below were
216 given, and the user's <code>Accept-Language</code> header assigned
217 <code>en</code> and <code>de</code> each as quality <code>.500</code>
218 (equally acceptable) then the first matching variant, <code>en</code>,
222 LanguagePriority en fr de<br />
223 ForceLanguagePriority Prefer
226 <p><code>ForceLanguagePriority Fallback</code> uses
227 <directive module="mod_negotiation">LanguagePriority</directive> to
228 serve a valid result, rather than returning an HTTP result 406
229 (NOT ACCEPTABLE). If the directives below were given, and the user's
230 <code>Accept-Language</code> only permitted an <code>es</code>
231 language response, but such a variant isn't found, then the first
232 variant from the <directive module="mod_negotiation"
233 >LanguagePriority</directive> list below will be served.</p>
236 LanguagePriority en fr de<br />
237 ForceLanguagePriority Fallback
240 <p>Both options, <code>Prefer</code> and <code>Fallback</code>, may be
241 specified, so either the first matching variant from <directive
242 module="mod_negotiation">LanguagePriority</directive> will be served if
243 more than one variant is acceptable, or first available document will
244 be served if none of the variants matched the client's acceptable list
247 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
251 <name>LanguagePriority</name>
252 <description>The precendence of language variants for cases where
253 the client does not express a preference</description>
254 <syntax>LanguagePriority <var>MIME-lang</var> [<var>MIME-lang</var>]
256 <contextlist><context>server config</context><context>virtual host</context>
257 <context>directory</context><context>.htaccess</context></contextlist>
258 <override>FileInfo</override>
261 <p>The <directive>LanguagePriority</directive> sets the precedence
262 of language variants for the case where the client does not
263 express a preference, when handling a MultiViews request. The list
264 of <var>MIME-lang</var> are in order of decreasing preference.</p>
266 <example><title>Example:</title>
267 LanguagePriority en fr de
270 <p>For a request for <code>foo.html</code>, where
271 <code>foo.html.fr</code> and <code>foo.html.de</code> both
272 existed, but the browser did not express a language preference,
273 then <code>foo.html.fr</code> would be returned.</p>
275 <p>Note that this directive only has an effect if a 'best'
276 language cannot be determined by any other means or the <directive
277 module="mod_negotiation">ForceLanguagePriority</directive> directive
278 is not <code>None</code>. In general, the client determines the
279 language preference, not the server.</p>
281 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>