2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_negotiation.xml.meta">
25 <name>mod_negotiation</name>
26 <description>Provides for <a
27 href="../content-negotiation.html">content negotiation</a></description>
29 <sourcefile>mod_negotiation.c</sourcefile>
30 <identifier>negotiation_module</identifier>
33 <p>Content negotiation, or more accurately content selection, is
34 the selection of the document that best matches the clients
35 capabilities, from one of several available documents. There
36 are two implementations of this.</p>
39 <li>A type map (a file with the handler
40 <code>type-map</code>) which explicitly lists the files
41 containing the variants.</li>
43 <li>A Multiviews search (enabled by the <code>Multiviews</code>
44 <directive module="core">Options</directive>), where the server does
45 an implicit filename pattern match, and choose from amongst the
49 <seealso><directive module="core">Options</directive></seealso>
50 <seealso><module>mod_mime</module></seealso>
51 <seealso><a href="../content-negotiation.html">Content
52 Negotiation</a></seealso>
53 <seealso><a href="../env.html">Environment Variables</a></seealso>
55 <section id="typemaps"><title>Type maps</title>
56 <p>A type map has a format similar to RFC822 mail headers. It
57 contains document descriptions separated by blank lines, with
58 lines beginning with a hash character ('#') treated as
59 comments. A document description consists of several header
60 records; records may be continued on multiple lines if the
61 continuation lines start with spaces. The leading space will be
62 deleted and the lines concatenated. A header record consists of
63 a keyword name, which always ends in a colon, followed by a
64 value. Whitespace is allowed between the header name and value,
65 and between the tokens of value. The headers allowed are: </p>
68 <dt><code>Content-Encoding:</code></dt>
69 <dd>The encoding of the file. Apache only recognizes
70 encodings that are defined by an <directive
71 module="mod_mime">AddEncoding</directive> directive.
72 This normally includes the encodings <code>x-compress</code>
73 for compress'd files, and <code>x-gzip</code> for gzip'd
74 files. The <code>x-</code> prefix is ignored for encoding
77 <dt><code>Content-Language:</code></dt>
78 <dd>The language(s) of the variant, as an Internet standard
79 language tag (<a href="http://www.ietf.org/rfc/rfc1766.txt"
80 >RFC 1766</a>). An example is <code>en</code>,
81 meaning English. If the variant contains more than one
82 language, they are separated by a comma.</dd>
84 <dt><code>Content-Length:</code></dt>
85 <dd>The length of the file, in bytes. If this header is not
86 present, then the actual length of the file is used.</dd>
88 <dt><code>Content-Type:</code></dt>
91 The <glossary ref="mime-type">MIME media type</glossary> of
92 the document, with optional parameters. Parameters are
93 separated from the media type and from one another by a
94 semi-colon, with a syntax of <code>name=value</code>. Common
98 <dt><code>level</code></dt>
99 <dd>an integer specifying the version of the media type.
100 For <code>text/html</code> this defaults to 2, otherwise
103 <dt><code>qs</code></dt>
104 <dd>a floating-point number with a value in the range 0[.000]
105 to 1[.000], indicating the relative 'quality' of this variant
106 compared to the other available variants, independent of
107 the client's capabilities. For example, a jpeg file is
108 usually of higher source quality than an ascii file if it
109 is attempting to represent a photograph. However, if the
110 resource being represented is ascii art, then an ascii
111 file would have a higher source quality than a jpeg file.
112 All <code>qs</code> values are therefore specific to a given
116 <example><title>Example</title>
117 Content-Type: image/jpeg; qs=0.8
121 <dt><code>URI:</code></dt>
122 <dd>uri of the file containing the variant (of the given
123 media type, encoded with the given content encoding). These
124 are interpreted as URLs relative to the map file; they must
125 be on the same server, and they must refer to files to
126 which the client would be granted access if they were to be
127 requested directly.</dd>
129 <dt><code>Body:</code></dt>
130 <dd>The actual content of the resource may
131 be included in the type-map file using the Body header. This
132 header must contain a string that designates a delimiter for
133 the body content. Then all following lines in the type map
134 file will be considered part of the resource body until the
135 delimiter string is found.
137 <example><title>Example:</title>
138 Body:----xyz----<br />
141 <p>Content of the page.</p><br />
149 <p>Consider, for example, a resource called
150 <code>document.html</code> which is available in English, French,
151 and German. The files for each of these are called
152 <code>document.html.en</code>, <code>document.html.fr</code>, and
153 <code>document.html.de</code>, respectively. The type map file will
154 be called <code>document.html.var</code>, and will contain the
158 URI: document.html<br />
160 Content-language: en<br />
161 Content-type: text/html<br />
162 URI: document.html.en<br />
164 Content-language: fr<br />
165 Content-type: text/html<br />
166 URI: document.html.fr<br />
168 Content-language: de<br />
169 Content-type: text/html<br />
170 URI: document.html.de<br />
175 <p>All four of these files should be placed in the same directory,
176 and the <code>.var</code> file should be associated with the
177 <code>type-map</code> handler with an <directive
178 module="mod_mime">AddHandler</directive> directive:</p>
180 <highlight language="config">
181 AddHandler type-map .var
184 <p>A request for <code>document.html</code> in this directory will
185 result in <code>document.html.var</code> being consulted, and the
186 variant chosen which most closely matches the language preference
187 specified in the user's <code>Accept-Language</code> request
191 <section id="multiviews"><title>Multiviews</title>
192 <p>A Multiviews search is enabled by the <code>Multiviews</code>
193 <directive module="core">Options</directive>. If the server receives a
194 request for <code>/some/dir/foo</code> and
195 <code>/some/dir/foo</code> does <em>not</em> exist, then the
196 server reads the directory looking for all files named
197 <code>foo.*</code>, and effectively fakes up a type map which
198 names all those files, assigning them the same media types and
199 content-encodings it would have if the client had asked for one
200 of them by name. It then chooses the best match to the client's
201 requirements, and returns that document.</p>
203 <p>The <directive module="mod_mime">MultiviewsMatch</directive>
204 directive configures whether Apache will consider files
205 that do not have content negotiation meta-information assigned
206 to them when choosing files.</p>
210 <name>CacheNegotiatedDocs</name>
211 <description>Allows content-negotiated documents to be
212 cached by proxy servers</description>
213 <syntax>CacheNegotiatedDocs On|Off</syntax>
214 <default>CacheNegotiatedDocs Off</default>
215 <contextlist><context>server config</context><context>virtual host</context>
219 <p>If set, this directive allows content-negotiated documents
220 to be cached by proxy servers. This could mean that clients
221 behind those proxys could retrieve versions of the documents
222 that are not the best match for their abilities, but it will
223 make caching more efficient.</p>
225 <p>This directive only applies to requests which come from
226 HTTP/1.0 browsers. HTTP/1.1 provides much better control over
227 the caching of negotiated documents, and this directive has no
228 effect in responses to HTTP/1.1 requests.</p>
234 <name>ForceLanguagePriority</name>
235 <description>Action to take if a single acceptable document is not
237 <syntax>ForceLanguagePriority None|Prefer|Fallback [Prefer|Fallback]</syntax>
238 <default>ForceLanguagePriority Prefer</default>
239 <contextlist><context>server config</context><context>virtual host</context>
240 <context>directory</context><context>.htaccess</context></contextlist>
241 <override>FileInfo</override>
244 <p>The <directive>ForceLanguagePriority</directive> directive uses
246 module="mod_negotiation">LanguagePriority</directive> to satisfy
247 negotiation where the server could otherwise not return a single
248 matching document.</p>
250 <p><code>ForceLanguagePriority Prefer</code> uses
251 <code>LanguagePriority</code> to serve a one valid result, rather
252 than returning an HTTP result 300 (MULTIPLE CHOICES) when there
253 are several equally valid choices. If the directives below were
254 given, and the user's <code>Accept-Language</code> header assigned
255 <code>en</code> and <code>de</code> each as quality <code>.500</code>
256 (equally acceptable) then the first matching variant, <code>en</code>,
259 <highlight language="config">
260 LanguagePriority en fr de
261 ForceLanguagePriority Prefer
264 <p><code>ForceLanguagePriority Fallback</code> uses
265 <directive module="mod_negotiation">LanguagePriority</directive> to
266 serve a valid result, rather than returning an HTTP result 406
267 (NOT ACCEPTABLE). If the directives below were given, and the user's
268 <code>Accept-Language</code> only permitted an <code>es</code>
269 language response, but such a variant isn't found, then the first
270 variant from the <directive module="mod_negotiation"
271 >LanguagePriority</directive> list below will be served.</p>
273 <highlight language="config">
274 LanguagePriority en fr de
275 ForceLanguagePriority Fallback
278 <p>Both options, <code>Prefer</code> and <code>Fallback</code>, may be
279 specified, so either the first matching variant from <directive
280 module="mod_negotiation">LanguagePriority</directive> will be served if
281 more than one variant is acceptable, or first available document will
282 be served if none of the variants matched the client's acceptable list
285 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
289 <name>LanguagePriority</name>
290 <description>The precendence of language variants for cases where
291 the client does not express a preference</description>
292 <syntax>LanguagePriority <var>MIME-lang</var> [<var>MIME-lang</var>]
294 <contextlist><context>server config</context><context>virtual host</context>
295 <context>directory</context><context>.htaccess</context></contextlist>
296 <override>FileInfo</override>
299 <p>The <directive>LanguagePriority</directive> sets the precedence
300 of language variants for the case where the client does not
301 express a preference, when handling a Multiviews request. The list
302 of <var>MIME-lang</var> are in order of decreasing preference.</p>
304 <highlight language="config">
305 LanguagePriority en fr de
308 <p>For a request for <code>foo.html</code>, where
309 <code>foo.html.fr</code> and <code>foo.html.de</code> both
310 existed, but the browser did not express a language preference,
311 then <code>foo.html.fr</code> would be returned.</p>
313 <p>Note that this directive only has an effect if a 'best'
314 language cannot be determined by any other means or the <directive
315 module="mod_negotiation">ForceLanguagePriority</directive> directive
316 is not <code>None</code>. In general, the client determines the
317 language preference, not the server.</p>
319 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>