]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_negotiation.xml
Update copyright year to 2005 and standardize on current copyright owner line.
[apache] / docs / manual / mod / mod_negotiation.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Copyright 2002-2005 The Apache Software Foundation or its licensors, as
8  applicable.
9
10  Licensed under the Apache License, Version 2.0 (the "License");
11  you may not use this file except in compliance with the License.
12  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="mod_negotiation.xml.meta">
24
25 <name>mod_negotiation</name>
26 <description>Provides for <a
27     href="../content-negotiation.html">content negotiation</a></description>
28 <status>Base</status>
29 <sourcefile>mod_negotiation.c</sourcefile>
30 <identifier>negotiation_module</identifier>
31
32 <summary>
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>
37
38     <ul>
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>
42
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
46       results.</li>
47     </ul>
48 </summary>
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>
54
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>
66
67     <dl>
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
75       comparisons.</dd>
76
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>
83
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>
87
88       <dt><code>Content-Type:</code></dt>
89
90       <dd>
91         The MIME media type of the document, with optional
92         parameters. Parameters are separated from the media type
93         and from one another by a semi-colon, with a syntax of
94         <code>name=value</code>. Common parameters include: 
95
96         <dl>
97           <dt><code>level</code></dt>
98           <dd>an integer specifying the version of the media type.
99           For <code>text/html</code> this defaults to 2, otherwise
100           0.</dd>
101
102           <dt><code>qs</code></dt>
103           <dd>a floating-point number with a value in the range 0.0
104           to 1.0, indicating the relative 'quality' of this variant
105           compared to the other available variants, independent of
106           the client's capabilities. For example, a jpeg file is
107           usually of higher source quality than an ascii file if it
108           is attempting to represent a photograph. However, if the
109           resource being represented is ascii art, then an ascii
110           file would have a higher source quality than a jpeg file.
111           All <code>qs</code> values are therefore specific to a given
112           resource.</dd>
113         </dl>
114
115         <example><title>Example</title>
116           Content-Type: image/jpeg; qs=0.8
117         </example>
118       </dd>
119
120       <dt><code>URI:</code></dt>
121       <dd>uri of the file containing the variant (of the given
122       media type, encoded with the given content encoding). These
123       are interpreted as URLs relative to the map file; they must
124       be on the same server (!), and they must refer to files to
125       which the client would be granted access if they were to be
126       requested directly.</dd>
127
128       <dt><code>Body:</code></dt>
129       <dd>New in Apache 2.0, the actual content of the resource may
130       be included in the type-map file using the Body header.  This
131       header must contain a string that designates a delimiter for
132       the body content. Then all following lines in the type map
133       file will be considered part of the resource body until the
134       delimiter string is found.
135
136       <example><title>Example:</title>
137         Body:----xyz----<br />
138         &lt;html&gt;<br />
139         &lt;body&gt;<br />
140         &lt;p&gt;Content of the page.&lt;/p&gt;<br />
141         &lt;/body&gt;<br />
142         &lt;/html&gt;<br />
143         ----xyz----
144       </example>
145       </dd>
146     </dl>
147 </section>
148
149 <section id="multiviews"><title>MultiViews</title>
150     <p>A MultiViews search is enabled by the <code>MultiViews</code>
151     <directive module="core">Options</directive>. If the server receives a
152     request for <code>/some/dir/foo</code> and
153     <code>/some/dir/foo</code> does <em>not</em> exist, then the
154     server reads the directory looking for all files named
155     <code>foo.*</code>, and effectively fakes up a type map which
156     names all those files, assigning them the same media types and
157     content-encodings it would have if the client had asked for one
158     of them by name. It then chooses the best match to the client's
159     requirements, and returns that document.</p>
160
161     <p>The <directive module="mod_mime">MultiViewsMatch</directive>
162     directive configures whether Apache will consider files
163     that do not have content negotiation meta-information assigned
164     to them when choosing files.</p>
165 </section>
166
167 <directivesynopsis>
168 <name>CacheNegotiatedDocs</name>
169 <description>Allows content-negotiated documents to be 
170 cached by proxy servers</description>
171 <syntax>CacheNegotiatedDocs On|Off</syntax>
172 <default>CacheNegotiatedDocs Off</default>
173 <contextlist><context>server config</context><context>virtual host</context>
174 </contextlist>
175 <compatibility>The syntax changed in version 2.0.</compatibility>
176
177 <usage>
178     <p>If set, this directive allows content-negotiated documents
179     to be cached by proxy servers. This could mean that clients
180     behind those proxys could retrieve versions of the documents
181     that are not the best match for their abilities, but it will
182     make caching more efficient.</p>
183
184     <p>This directive only applies to requests which come from
185     HTTP/1.0 browsers. HTTP/1.1 provides much better control over
186     the caching of negotiated documents, and this directive has no
187     effect in responses to HTTP/1.1 requests.</p>
188
189     <p>Prior to version 2.0,
190     <directive>CacheNegotiatedDocs</directive> did not take an
191     argument; it was turned on by the presence of the directive by
192     itself.</p>
193 </usage>
194 </directivesynopsis>
195
196 <directivesynopsis>
197 <name>ForceLanguagePriority</name>
198 <description>Action to take if a single acceptable document is not 
199 found</description>
200 <syntax>ForceLanguagePriority None|Prefer|Fallback [Prefer|Fallback]</syntax>
201 <default>ForceLanguagePriority Prefer</default>
202 <contextlist><context>server config</context><context>virtual host</context>
203 <context>directory</context><context>.htaccess</context></contextlist>
204 <override>FileInfo</override>
205 <compatibility>Available in version 2.0.30 and later</compatibility>
206
207 <usage>
208     <p>The <directive>ForceLanguagePriority</directive> directive uses
209     the given <directive
210     module="mod_negotiation">LanguagePriority</directive> to satisfy
211     negotation where the server could otherwise not return a single
212     matching document.</p>
213
214     <p><code>ForceLanguagePriority Prefer</code> uses
215     <code>LanguagePriority</code> to serve a one valid result, rather
216     than returning an HTTP result 300 (MULTIPLE CHOICES) when there
217     are several equally valid choices.  If the directives below were
218     given, and the user's <code>Accept-Language</code> header assigned
219     <code>en</code> and <code>de</code> each as quality <code>.500</code>
220     (equally acceptable) then the first matching variant, <code>en</code>,
221     will be served.</p>
222
223     <example>
224       LanguagePriority en fr de<br />
225       ForceLanguagePriority Prefer
226     </example>
227
228     <p><code>ForceLanguagePriority Fallback</code> uses
229     <directive module="mod_negotiation">LanguagePriority</directive> to
230     serve a valid result, rather than returning an HTTP result 406
231     (NOT ACCEPTABLE). If the directives below were given, and the user's
232     <code>Accept-Language</code> only permitted an <code>es</code>
233     language response, but such a variant isn't found, then the first
234     variant from the <directive module="mod_negotiation"
235     >LanguagePriority</directive> list below will be served.</p>
236
237     <example>
238       LanguagePriority en fr de<br />
239       ForceLanguagePriority Fallback
240     </example>
241
242     <p>Both options, <code>Prefer</code> and <code>Fallback</code>, may be
243     specified, so either the first matching variant from <directive
244     module="mod_negotiation">LanguagePriority</directive> will be served if
245     more than one variant is acceptable, or first available document will
246     be served if none of the variants matched the client's acceptable list
247     of languages.</p>
248 </usage>
249 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
250 </directivesynopsis>
251
252 <directivesynopsis>
253 <name>LanguagePriority</name>
254 <description>The precendence of language variants for cases where
255 the client does not express a preference</description>
256 <syntax>LanguagePriority <var>MIME-lang</var> [<var>MIME-lang</var>]
257 ...</syntax>
258 <contextlist><context>server config</context><context>virtual host</context>
259 <context>directory</context><context>.htaccess</context></contextlist>
260 <override>FileInfo</override>
261
262 <usage>
263     <p>The <directive>LanguagePriority</directive> sets the precedence
264     of language variants for the case where the client does not
265     express a preference, when handling a MultiViews request. The list
266     of <var>MIME-lang</var> are in order of decreasing preference.</p>
267
268     <example><title>Example:</title>
269       LanguagePriority en fr de
270     </example>
271
272     <p>For a request for <code>foo.html</code>, where
273     <code>foo.html.fr</code> and <code>foo.html.de</code> both
274     existed, but the browser did not express a language preference,
275     then <code>foo.html.fr</code> would be returned.</p>
276
277     <p>Note that this directive only has an effect if a 'best'
278     language cannot be determined by any other means or the <directive
279     module="mod_negotiation">ForceLanguagePriority</directive> directive
280     is not <code>None</code>. In general, the client determines the
281     language preference, not the server.</p>
282 </usage>
283 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
284 </directivesynopsis>
285
286 </modulesynopsis>