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.var</code> in this directory will
185 result in choosing the variant which most closely matches the language preference
186 specified in the user's <code>Accept-Language</code> request
189 <p>If <code>Multiviews</code> is enabled, and <directive module="mod_mime"
190 >MultiviewsMatch</directive> is set to "handlers" or "any", a request to
191 <code>document.html</code> will discover <code>document.html.var</code> and
192 continue negotiating with the explicit type map.</p>
194 <p>Other configuration directives, such as <directive module="mod_alias"
195 >Alias</directive> can be used to map <code>document.html</code> to
196 <code>document.html.var</code></p>.
200 <section id="multiviews"><title>Multiviews</title>
201 <p>A Multiviews search is enabled by the <code>Multiviews</code>
202 <directive module="core">Options</directive>. If the server receives a
203 request for <code>/some/dir/foo</code> and
204 <code>/some/dir/foo</code> does <em>not</em> exist, then the
205 server reads the directory looking for all files named
206 <code>foo.*</code>, and effectively fakes up a type map which
207 names all those files, assigning them the same media types and
208 content-encodings it would have if the client had asked for one
209 of them by name. It then chooses the best match to the client's
210 requirements, and returns that document.</p>
212 <p>The <directive module="mod_mime">MultiviewsMatch</directive>
213 directive configures whether Apache will consider files
214 that do not have content negotiation meta-information assigned
215 to them when choosing files.</p>
219 <name>CacheNegotiatedDocs</name>
220 <description>Allows content-negotiated documents to be
221 cached by proxy servers</description>
222 <syntax>CacheNegotiatedDocs On|Off</syntax>
223 <default>CacheNegotiatedDocs Off</default>
224 <contextlist><context>server config</context><context>virtual host</context>
228 <p>If set, this directive allows content-negotiated documents
229 to be cached by proxy servers. This could mean that clients
230 behind those proxys could retrieve versions of the documents
231 that are not the best match for their abilities, but it will
232 make caching more efficient.</p>
234 <p>This directive only applies to requests which come from
235 HTTP/1.0 browsers. HTTP/1.1 provides much better control over
236 the caching of negotiated documents, and this directive has no
237 effect in responses to HTTP/1.1 requests.</p>
243 <name>ForceLanguagePriority</name>
244 <description>Action to take if a single acceptable document is not
246 <syntax>ForceLanguagePriority None|Prefer|Fallback [Prefer|Fallback]</syntax>
247 <default>ForceLanguagePriority Prefer</default>
248 <contextlist><context>server config</context><context>virtual host</context>
249 <context>directory</context><context>.htaccess</context></contextlist>
250 <override>FileInfo</override>
253 <p>The <directive>ForceLanguagePriority</directive> directive uses
255 module="mod_negotiation">LanguagePriority</directive> to satisfy
256 negotiation where the server could otherwise not return a single
257 matching document.</p>
259 <p><code>ForceLanguagePriority Prefer</code> uses
260 <code>LanguagePriority</code> to serve a one valid result, rather
261 than returning an HTTP result 300 (MULTIPLE CHOICES) when there
262 are several equally valid choices. If the directives below were
263 given, and the user's <code>Accept-Language</code> header assigned
264 <code>en</code> and <code>de</code> each as quality <code>.500</code>
265 (equally acceptable) then the first matching variant, <code>en</code>,
268 <highlight language="config">
269 LanguagePriority en fr de
270 ForceLanguagePriority Prefer
273 <p><code>ForceLanguagePriority Fallback</code> uses
274 <directive module="mod_negotiation">LanguagePriority</directive> to
275 serve a valid result, rather than returning an HTTP result 406
276 (NOT ACCEPTABLE). If the directives below were given, and the user's
277 <code>Accept-Language</code> only permitted an <code>es</code>
278 language response, but such a variant isn't found, then the first
279 variant from the <directive module="mod_negotiation"
280 >LanguagePriority</directive> list below will be served.</p>
282 <highlight language="config">
283 LanguagePriority en fr de
284 ForceLanguagePriority Fallback
287 <p>Both options, <code>Prefer</code> and <code>Fallback</code>, may be
288 specified, so either the first matching variant from <directive
289 module="mod_negotiation">LanguagePriority</directive> will be served if
290 more than one variant is acceptable, or first available document will
291 be served if none of the variants matched the client's acceptable list
294 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
298 <name>LanguagePriority</name>
299 <description>The precendence of language variants for cases where
300 the client does not express a preference</description>
301 <syntax>LanguagePriority <var>MIME-lang</var> [<var>MIME-lang</var>]
303 <contextlist><context>server config</context><context>virtual host</context>
304 <context>directory</context><context>.htaccess</context></contextlist>
305 <override>FileInfo</override>
308 <p>The <directive>LanguagePriority</directive> sets the precedence
309 of language variants for the case where the client does not
310 express a preference, when handling a Multiviews request. The list
311 of <var>MIME-lang</var> are in order of decreasing preference.</p>
313 <highlight language="config">
314 LanguagePriority en fr de
317 <p>For a request for <code>foo.html</code>, where
318 <code>foo.html.fr</code> and <code>foo.html.de</code> both
319 existed, but the browser did not express a language preference,
320 then <code>foo.html.fr</code> would be returned.</p>
322 <p>Note that this directive only has an effect if a 'best'
323 language cannot be determined by any other means or the <directive
324 module="mod_negotiation">ForceLanguagePriority</directive> directive
325 is not <code>None</code>. In general, the client determines the
326 language preference, not the server.</p>
328 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>