1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>Content Negotiation - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.min.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body id="manual-page"><div id="page-header"> 17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 18<p class="apache">Apache HTTP Server Version 2.4</p> 19<img alt="" src="/images/feather.gif" /></div> 20<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 21<div id="path"> 22<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="./">Version 2.4</a></div><div id="page-content"><div id="preamble"><h1>Content Negotiation</h1> 23<div class="toplang"> 24<p><span>Available Languages: </span><a href="/en/content-negotiation.html" title="English"> en </a> | 25<a href="/fr/content-negotiation.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 26<a href="/ja/content-negotiation.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 27<a href="/ko/content-negotiation.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 28<a href="/tr/content-negotiation.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 29</div> 30 31 32 <p>Apache HTTPD supports content negotiation as described in 33 the HTTP/1.1 specification. It can choose the best 34 representation of a resource based on the browser-supplied 35 preferences for media type, languages, character set and 36 encoding. It also implements a couple of features to give 37 more intelligent handling of requests from browsers that send 38 incomplete negotiation information.</p> 39 40 <p>Content negotiation is provided by the 41 <code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code> module, which is compiled in 42 by default.</p> 43</div> 44<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#about">About Content Negotiation</a></li> 45<li><img alt="" src="/images/down.gif" /> <a href="#negotiation">Negotiation in httpd</a></li> 46<li><img alt="" src="/images/down.gif" /> <a href="#methods">The Negotiation Methods</a></li> 47<li><img alt="" src="/images/down.gif" /> <a href="#better">Fiddling with Quality 48 Values</a></li> 49<li><img alt="" src="/images/down.gif" /> <a href="#extensions">Extensions to Transparent Content 50Negotiation</a></li> 51<li><img alt="" src="/images/down.gif" /> <a href="#naming">Note on hyperlinks and naming conventions</a></li> 52<li><img alt="" src="/images/down.gif" /> <a href="#caching">Note on Caching</a></li> 53</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 54<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 55<div class="section"> 56<h2><a name="about" id="about">About Content Negotiation</a></h2> 57 58 <p>A resource may be available in several different 59 representations. For example, it might be available in 60 different languages or different media types, or a combination. 61 One way of selecting the most appropriate choice is to give the 62 user an index page, and let them select. However it is often 63 possible for the server to choose automatically. This works 64 because browsers can send, as part of each request, information 65 about what representations they prefer. For example, a browser 66 could indicate that it would like to see information in French, 67 if possible, else English will do. Browsers indicate their 68 preferences by headers in the request. To request only French 69 representations, the browser would send</p> 70 71<div class="example"><p><code>Accept-Language: fr</code></p></div> 72 73 <p>Note that this preference will only be applied when there is 74 a choice of representations and they vary by language.</p> 75 76 <p>As an example of a more complex request, this browser has 77 been configured to accept French and English, but prefer 78 French, and to accept various media types, preferring HTML over 79 plain text or other text types, and preferring GIF or JPEG over 80 other media types, but also allowing any other media type as a 81 last resort:</p> 82 83<div class="example"><p><code> 84 Accept-Language: fr; q=1.0, en; q=0.5<br /> 85 Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1 86</code></p></div> 87 88 <p>httpd supports 'server driven' content negotiation, as 89 defined in the HTTP/1.1 specification. It fully supports the 90 <code>Accept</code>, <code>Accept-Language</code>, 91 <code>Accept-Charset</code> and <code>Accept-Encoding</code> 92 request headers. httpd also supports 'transparent' 93 content negotiation, which is an experimental negotiation 94 protocol defined in RFC 2295 and RFC 2296. It does not offer 95 support for 'feature negotiation' as defined in these RFCs.</p> 96 97 <p>A <strong>resource</strong> is a conceptual entity 98 identified by a URI (RFC 2396). An HTTP server like Apache HTTP Server 99 provides access to <strong>representations</strong> of the 100 resource(s) within its namespace, with each representation in 101 the form of a sequence of bytes with a defined media type, 102 character set, encoding, etc. Each resource may be associated 103 with zero, one, or more than one representation at any given 104 time. If multiple representations are available, the resource 105 is referred to as <strong>negotiable</strong> and each of its 106 representations is termed a <strong>variant</strong>. The ways 107 in which the variants for a negotiable resource vary are called 108 the <strong>dimensions</strong> of negotiation.</p> 109</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 110<div class="section"> 111<h2><a name="negotiation" id="negotiation">Negotiation in httpd</a></h2> 112 113 <p>In order to negotiate a resource, the server needs to be 114 given information about each of the variants. This is done in 115 one of two ways:</p> 116 117 <ul> 118 <li>Using a type map (<em>i.e.</em>, a <code>*.var</code> 119 file) which names the files containing the variants 120 explicitly, or</li> 121 122 <li>Using a 'MultiViews' search, where the server does an 123 implicit filename pattern match and chooses from among the 124 results.</li> 125 </ul> 126 127 <h3><a name="type-map" id="type-map">Using a type-map file</a></h3> 128 129 <p>A type map is a document which is associated with the handler 130 named <code>type-map</code> (or, for backwards-compatibility with 131 older httpd configurations, the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> 132 <code>application/x-type-map</code>). Note that to use this 133 feature, you must have a handler set in the configuration that 134 defines a file suffix as <code>type-map</code>; this is best done 135 with</p> 136 137<pre class="prettyprint lang-config">AddHandler type-map .var</pre> 138 139 140 <p>in the server configuration file.</p> 141 142 <p>Type map files should have the same name as the resource 143 which they are describing, followed by the extension 144 <code>.var</code>. In the examples shown below, the resource is 145 named <code>foo</code>, so the type map file is named 146 <code>foo.var</code>.</p> 147 148 <p>This file should have an entry for each available 149 variant; these entries consist of contiguous HTTP-format header 150 lines. Entries for different variants are separated by blank 151 lines. Blank lines are illegal within an entry. It is 152 conventional to begin a map file with an entry for the combined 153 entity as a whole (although this is not required, and if 154 present will be ignored). An example map file is shown below.</p> 155 156 <p>URIs in this file are relative to the location of the type map 157 file. Usually, these files will be located in the same directory as 158 the type map file, but this is not required. You may provide 159 absolute or relative URIs for any file located on the same server as 160 the map file.</p> 161 162<div class="example"><p><code> 163 URI: foo<br /> 164<br /> 165 URI: foo.en.html<br /> 166 Content-type: text/html<br /> 167 Content-language: en<br /> 168<br /> 169 URI: foo.fr.de.html<br /> 170 Content-type: text/html;charset=iso-8859-2<br /> 171 Content-language: fr, de<br /> 172</code></p></div> 173 174 <p>Note also that a typemap file will take precedence over the 175 filename's extension, even when Multiviews is on. If the 176 variants have different source qualities, that may be indicated 177 by the "qs" parameter to the media type, as in this picture 178 (available as JPEG, GIF, or ASCII-art): </p> 179 180<div class="example"><p><code> 181 URI: foo<br /> 182<br /> 183 URI: foo.jpeg<br /> 184 Content-type: image/jpeg; qs=0.8<br /> 185<br /> 186 URI: foo.gif<br /> 187 Content-type: image/gif; qs=0.5<br /> 188<br /> 189 URI: foo.txt<br /> 190 Content-type: text/plain; qs=0.01<br /> 191</code></p></div> 192 193 <p>qs values can vary in the range 0.000 to 1.000. Note that 194 any variant with a qs value of 0.000 will never be chosen. 195 Variants with no 'qs' parameter value are given a qs factor of 196 1.0. The qs parameter indicates the relative 'quality' of this 197 variant compared to the other available variants, independent 198 of the client's capabilities. For example, a JPEG file is 199 usually of higher source quality than an ASCII file if it is 200 attempting to represent a photograph. However, if the resource 201 being represented is an original ASCII art, then an ASCII 202 representation would have a higher source quality than a JPEG 203 representation. A qs value is therefore specific to a given 204 variant depending on the nature of the resource it 205 represents.</p> 206 207 <p>The full list of headers recognized is available in the <a href="mod/mod_negotiation.html#typemaps">mod_negotiation 208 typemap</a> documentation.</p> 209 210 211<h3><a name="multiviews" id="multiviews">Multiviews</a></h3> 212 213 <p><code>MultiViews</code> is a per-directory option, meaning it 214 can be set with an <code class="directive"><a href="/mod/core.html#options">Options</a></code> 215 directive within a <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code>, <code class="directive"><a href="/mod/core.html#location"><Location></a></code> or <code class="directive"><a href="/mod/core.html#files"><Files></a></code> section in 216 <code>httpd.conf</code>, or (if <code class="directive"><a href="/mod/core.html#allowoverride">AllowOverride</a></code> is properly set) in 217 <code>.htaccess</code> files. Note that <code>Options All</code> 218 does not set <code>MultiViews</code>; you have to ask for it by 219 name.</p> 220 221 <p>The effect of <code>MultiViews</code> is as follows: if the 222 server receives a request for <code>/some/dir/foo</code>, if 223 <code>/some/dir</code> has <code>MultiViews</code> enabled, and 224 <code>/some/dir/foo</code> does <em>not</em> exist, then the 225 server reads the directory looking for files named foo.*, and 226 effectively fakes up a type map which names all those files, 227 assigning them the same media types and content-encodings it 228 would have if the client had asked for one of them by name. It 229 then chooses the best match to the client's requirements.</p> 230 231 <p><code>MultiViews</code> may also apply to searches for the file 232 named by the <code class="directive"><a href="/mod/mod_dir.html#directoryindex">DirectoryIndex</a></code> directive, if the 233 server is trying to index a directory. If the configuration files 234 specify</p> 235<pre class="prettyprint lang-config">DirectoryIndex index</pre> 236 237 <p>then the server will arbitrate between <code>index.html</code> 238 and <code>index.html3</code> if both are present. If neither 239 are present, and <code>index.cgi</code> is there, the server 240 will run it.</p> 241 242 <p>If one of the files found when reading the directory does not 243 have an extension recognized by <code>mod_mime</code> to designate 244 its Charset, Content-Type, Language, or Encoding, then the result 245 depends on the setting of the <code class="directive"><a href="/mod/mod_mime.html#multiviewsmatch">MultiViewsMatch</a></code> directive. This 246 directive determines whether handlers, filters, and other 247 extension types can participate in MultiViews negotiation.</p> 248 249</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 250<div class="section"> 251<h2><a name="methods" id="methods">The Negotiation Methods</a></h2> 252 253 <p>After httpd has obtained a list of the variants for a given 254 resource, either from a type-map file or from the filenames in 255 the directory, it invokes one of two methods to decide on the 256 'best' variant to return, if any. It is not necessary to know 257 any of the details of how negotiation actually takes place in 258 order to use httpd's content negotiation features. However the 259 rest of this document explains the methods used for those 260 interested. </p> 261 262 <p>There are two negotiation methods:</p> 263 264 <ol> 265 <li><strong>Server driven negotiation with the httpd 266 algorithm</strong> is used in the normal case. The httpd 267 algorithm is explained in more detail below. When this 268 algorithm is used, httpd can sometimes 'fiddle' the quality 269 factor of a particular dimension to achieve a better result. 270 The ways httpd can fiddle quality factors is explained in 271 more detail below.</li> 272 273 <li><strong>Transparent content negotiation</strong> is used 274 when the browser specifically requests this through the 275 mechanism defined in RFC 2295. This negotiation method gives 276 the browser full control over deciding on the 'best' variant, 277 the result is therefore dependent on the specific algorithms 278 used by the browser. As part of the transparent negotiation 279 process, the browser can ask httpd to run the 'remote 280 variant selection algorithm' defined in RFC 2296.</li> 281 </ol> 282 283<h3><a name="dimensions" id="dimensions">Dimensions of Negotiation</a></h3> 284 285 <table> 286 287 <tr valign="top"> 288 <th>Dimension</th> 289 290 <th>Notes</th> 291 </tr> 292 293 <tr valign="top"> 294 <td>Media Type</td> 295 296 <td>Browser indicates preferences with the <code>Accept</code> 297 header field. Each item can have an associated quality factor. 298 Variant description can also have a quality factor (the "qs" 299 parameter).</td> 300 </tr> 301 302 <tr valign="top"> 303 <td>Language</td> 304 305 <td>Browser indicates preferences with the 306 <code>Accept-Language</code> header field. Each item can have 307 a quality factor. Variants can be associated with none, one or 308 more than one language.</td> 309 </tr> 310 311 <tr valign="top"> 312 <td>Encoding</td> 313 314 <td>Browser indicates preference with the 315 <code>Accept-Encoding</code> header field. Each item can have 316 a quality factor.</td> 317 </tr> 318 319 <tr valign="top"> 320 <td>Charset</td> 321 322 <td>Browser indicates preference with the 323 <code>Accept-Charset</code> header field. Each item can have a 324 quality factor. Variants can indicate a charset as a parameter 325 of the media type.</td> 326 </tr> 327 </table> 328 329 330<h3><a name="algorithm" id="algorithm">httpd Negotiation Algorithm</a></h3> 331 332 <p>httpd can use the following algorithm to select the 'best' 333 variant (if any) to return to the browser. This algorithm is 334 not further configurable. It operates as follows:</p> 335 336 <ol> 337 <li>First, for each dimension of the negotiation, check the 338 appropriate <em>Accept*</em> header field and assign a 339 quality to each variant. If the <em>Accept*</em> header for 340 any dimension implies that this variant is not acceptable, 341 eliminate it. If no variants remain, go to step 4.</li> 342 343 <li> 344 Select the 'best' variant by a process of elimination. Each 345 of the following tests is applied in order. Any variants 346 not selected at each test are eliminated. After each test, 347 if only one variant remains, select it as the best match 348 and proceed to step 3. If more than one variant remains, 349 move on to the next test. 350 351 <ol> 352 <li>Multiply the quality factor from the <code>Accept</code> 353 header with the quality-of-source factor for this variants 354 media type, and select the variants with the highest 355 value.</li> 356 357 <li>Select the variants with the highest language quality 358 factor.</li> 359 360 <li>Select the variants with the best language match, 361 using either the order of languages in the 362 <code>Accept-Language</code> header (if present), or else 363 the order of languages in the <code>LanguagePriority</code> 364 directive (if present).</li> 365 366 <li>Select the variants with the highest 'level' media 367 parameter (used to give the version of text/html media 368 types).</li> 369 370 <li>Select variants with the best charset media 371 parameters, as given on the <code>Accept-Charset</code> 372 header line. Charset ISO-8859-1 is acceptable unless 373 explicitly excluded. Variants with a <code>text/*</code> 374 media type but not explicitly associated with a particular 375 charset are assumed to be in ISO-8859-1.</li> 376 377 <li>Select those variants which have associated charset 378 media parameters that are <em>not</em> ISO-8859-1. If 379 there are no such variants, select all variants 380 instead.</li> 381 382 <li>Select the variants with the best encoding. If there 383 are variants with an encoding that is acceptable to the 384 user-agent, select only these variants. Otherwise if 385 there is a mix of encoded and non-encoded variants, 386 select only the unencoded variants. If either all 387 variants are encoded or all variants are not encoded, 388 select all variants.</li> 389 390 <li>Select the variants with the smallest content 391 length.</li> 392 393 <li>Select the first variant of those remaining. This 394 will be either the first listed in the type-map file, or 395 when variants are read from the directory, the one whose 396 file name comes first when sorted using ASCII code 397 order.</li> 398 </ol> 399 </li> 400 401 <li>The algorithm has now selected one 'best' variant, so 402 return it as the response. The HTTP response header 403 <code>Vary</code> is set to indicate the dimensions of 404 negotiation (browsers and caches can use this information when 405 caching the resource). End.</li> 406 407 <li>To get here means no variant was selected (because none 408 are acceptable to the browser). Return a 406 status (meaning 409 "No acceptable representation") with a response body 410 consisting of an HTML document listing the available 411 variants. Also set the HTTP <code>Vary</code> header to 412 indicate the dimensions of variance.</li> 413 </ol> 414 415</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 416<div class="section"> 417<h2><a name="better" id="better">Fiddling with Quality 418 Values</a></h2> 419 420 <p>httpd sometimes changes the quality values from what would 421 be expected by a strict interpretation of the httpd 422 negotiation algorithm above. This is to get a better result 423 from the algorithm for browsers which do not send full or 424 accurate information. Some of the most popular browsers send 425 <code>Accept</code> header information which would otherwise 426 result in the selection of the wrong variant in many cases. If a 427 browser sends full and correct information these fiddles will not 428 be applied.</p> 429 430<h3><a name="wildcards" id="wildcards">Media Types and Wildcards</a></h3> 431 432 <p>The <code>Accept:</code> request header indicates preferences 433 for media types. It can also include 'wildcard' media types, such 434 as "image/*" or "*/*" where the * matches any string. So a request 435 including:</p> 436 437<div class="example"><p><code>Accept: image/*, */*</code></p></div> 438 439 <p>would indicate that any type starting "image/" is acceptable, 440 as is any other type. 441 Some browsers routinely send wildcards in addition to explicit 442 types they can handle. For example:</p> 443 444<div class="example"><p><code> 445 Accept: text/html, text/plain, image/gif, image/jpeg, */* 446</code></p></div> 447 <p>The intention of this is to indicate that the explicitly listed 448 types are preferred, but if a different representation is 449 available, that is ok too. Using explicit quality values, 450 what the browser really wants is something like:</p> 451<div class="example"><p><code> 452 Accept: text/html, text/plain, image/gif, image/jpeg, */*; q=0.01 453</code></p></div> 454 <p>The explicit types have no quality factor, so they default to a 455 preference of 1.0 (the highest). The wildcard */* is given a 456 low preference of 0.01, so other types will only be returned if 457 no variant matches an explicitly listed type.</p> 458 459 <p>If the <code>Accept:</code> header contains <em>no</em> q 460 factors at all, httpd sets the q value of "*/*", if present, to 461 0.01 to emulate the desired behavior. It also sets the q value of 462 wildcards of the format "type/*" to 0.02 (so these are preferred 463 over matches against "*/*". If any media type on the 464 <code>Accept:</code> header contains a q factor, these special 465 values are <em>not</em> applied, so requests from browsers which 466 send the explicit information to start with work as expected.</p> 467 468 469<h3><a name="exceptions" id="exceptions">Language Negotiation Exceptions</a></h3> 470 471 <p>New in httpd 2.0, some exceptions have been added to the 472 negotiation algorithm to allow graceful fallback when language 473 negotiation fails to find a match.</p> 474 475 <p>When a client requests a page on your server, but the server 476 cannot find a single page that matches the 477 <code>Accept-language</code> sent by 478 the browser, the server will return either a "No Acceptable 479 Variant" or "Multiple Choices" response to the client. To avoid 480 these error messages, it is possible to configure httpd to ignore 481 the <code>Accept-language</code> in these cases and provide a 482 document that does not explicitly match the client's request. The 483 <code class="directive"><a href="/mod/mod_negotiation.html#forcelanguagepriority">ForceLanguagePriority</a></code> 484 directive can be used to override one or both of these error 485 messages and substitute the servers judgement in the form of the 486 <code class="directive"><a href="/mod/mod_negotiation.html#languagepriority">LanguagePriority</a></code> 487 directive.</p> 488 489 <p>The server will also attempt to match language-subsets when no 490 other match can be found. For example, if a client requests 491 documents with the language <code>en-GB</code> for British 492 English, the server is not normally allowed by the HTTP/1.1 493 standard to match that against a document that is marked as simply 494 <code>en</code>. (Note that it is almost surely a configuration 495 error to include <code>en-GB</code> and not <code>en</code> in the 496 <code>Accept-Language</code> header, since it is very unlikely 497 that a reader understands British English, but doesn't understand 498 English in general. Unfortunately, many current clients have 499 default configurations that resemble this.) However, if no other 500 language match is possible and the server is about to return a "No 501 Acceptable Variants" error or fallback to the <code class="directive"><a href="/mod/mod_negotiation.html#languagepriority">LanguagePriority</a></code>, the server 502 will ignore the subset specification and match <code>en-GB</code> 503 against <code>en</code> documents. Implicitly, httpd will add 504 the parent language to the client's acceptable language list with 505 a very low quality value. But note that if the client requests 506 "en-GB; q=0.9, fr; q=0.8", and the server has documents 507 designated "en" and "fr", then the "fr" document will be returned. 508 This is necessary to maintain compliance with the HTTP/1.1 509 specification and to work effectively with properly configured 510 clients.</p> 511 512 <p>In order to support advanced techniques (such as cookies or 513 special URL-paths) to determine the user's preferred language, 514 since httpd 2.0.47 <code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code> recognizes 515 the <a href="env.html">environment variable</a> 516 <code>prefer-language</code>. If it exists and contains an 517 appropriate language tag, <code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code> will 518 try to select a matching variant. If there's no such variant, 519 the normal negotiation process applies.</p> 520 521 <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">SetEnvIf Cookie "language=(.+)" prefer-language=$1 522Header append Vary cookie</pre> 523</div> 524 525</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 526<div class="section"> 527<h2><a name="extensions" id="extensions">Extensions to Transparent Content 528Negotiation</a></h2> 529 530<p>httpd extends the transparent content negotiation protocol (RFC 5312295) as follows. A new <code>{encoding ..}</code> element is used in 532variant lists to label variants which are available with a specific 533content-encoding only. The implementation of the RVSA/1.0 algorithm 534(RFC 2296) is extended to recognize encoded variants in the list, and 535to use them as candidate variants whenever their encodings are 536acceptable according to the <code>Accept-Encoding</code> request 537header. The RVSA/1.0 implementation does not round computed quality 538factors to 5 decimal places before choosing the best variant.</p> 539</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 540<div class="section"> 541<h2><a name="naming" id="naming">Note on hyperlinks and naming conventions</a></h2> 542 543 <p>If you are using language negotiation you can choose between 544 different naming conventions, because files can have more than 545 one extension, and the order of the extensions is normally 546 irrelevant (see the <a href="mod/mod_mime.html#multipleext">mod_mime</a> documentation 547 for details).</p> 548 549 <p>A typical file has a MIME-type extension (<em>e.g.</em>, 550 <code>html</code>), maybe an encoding extension (<em>e.g.</em>, 551 <code>gz</code>), and of course a language extension 552 (<em>e.g.</em>, <code>en</code>) when we have different 553 language variants of this file.</p> 554 555 <p>Examples:</p> 556 557 <ul> 558 <li>foo.en.html</li> 559 560 <li>foo.html.en</li> 561 562 <li>foo.en.html.gz</li> 563 </ul> 564 565 <p>Here some more examples of filenames together with valid and 566 invalid hyperlinks:</p> 567 568 <table class="bordered"> 569 570 <tr> 571 <th>Filename</th> 572 573 <th>Valid hyperlink</th> 574 575 <th>Invalid hyperlink</th> 576 </tr> 577 578 <tr> 579 <td><em>foo.html.en</em></td> 580 581 <td>foo<br /> 582 foo.html</td> 583 584 <td>-</td> 585 </tr> 586 587 <tr> 588 <td><em>foo.en.html</em></td> 589 590 <td>foo</td> 591 592 <td>foo.html</td> 593 </tr> 594 595 <tr> 596 <td><em>foo.html.en.gz</em></td> 597 598 <td>foo<br /> 599 foo.html</td> 600 601 <td>foo.gz<br /> 602 foo.html.gz</td> 603 </tr> 604 605 <tr> 606 <td><em>foo.en.html.gz</em></td> 607 608 <td>foo</td> 609 610 <td>foo.html<br /> 611 foo.html.gz<br /> 612 foo.gz</td> 613 </tr> 614 615 <tr> 616 <td><em>foo.gz.html.en</em></td> 617 618 <td>foo<br /> 619 foo.gz<br /> 620 foo.gz.html</td> 621 622 <td>foo.html</td> 623 </tr> 624 625 <tr> 626 <td><em>foo.html.gz.en</em></td> 627 628 <td>foo<br /> 629 foo.html<br /> 630 foo.html.gz</td> 631 632 <td>foo.gz</td> 633 </tr> 634 </table> 635 636 <p>Looking at the table above, you will notice that it is always 637 possible to use the name without any extensions in a hyperlink 638 (<em>e.g.</em>, <code>foo</code>). The advantage is that you 639 can hide the actual type of a document rsp. file and can change 640 it later, <em>e.g.</em>, from <code>html</code> to 641 <code>shtml</code> or <code>cgi</code> without changing any 642 hyperlink references.</p> 643 644 <p>If you want to continue to use a MIME-type in your 645 hyperlinks (<em>e.g.</em> <code>foo.html</code>) the language 646 extension (including an encoding extension if there is one) 647 must be on the right hand side of the MIME-type extension 648 (<em>e.g.</em>, <code>foo.html.en</code>).</p> 649</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 650<div class="section"> 651<h2><a name="caching" id="caching">Note on Caching</a></h2> 652 653 <p>When a cache stores a representation, it associates it with 654 the request URL. The next time that URL is requested, the cache 655 can use the stored representation. But, if the resource is 656 negotiable at the server, this might result in only the first 657 requested variant being cached and subsequent cache hits might 658 return the wrong response. To prevent this, httpd normally 659 marks all responses that are returned after content negotiation 660 as non-cacheable by HTTP/1.0 clients. httpd also supports the 661 HTTP/1.1 protocol features to allow caching of negotiated 662 responses.</p> 663 664 <p>For requests which come from a HTTP/1.0 compliant client 665 (either a browser or a cache), the directive <code class="directive"><a href="/mod/mod_negotiation.html#cachenegotiateddocs">CacheNegotiatedDocs</a></code> can be 666 used to allow caching of responses which were subject to 667 negotiation. This directive can be given in the server config or 668 virtual host, and takes no arguments. It has no effect on requests 669 from HTTP/1.1 clients.</p> 670 671 <p>For HTTP/1.1 clients, httpd sends a <code>Vary</code> HTTP 672 response header to indicate the negotiation dimensions for the 673 response. Caches can use this information to determine whether a 674 subsequent request can be served from the local copy. To 675 encourage a cache to use the local copy regardless of the 676 negotiation dimensions, set the <code>force-no-vary</code> <a href="env.html#special">environment variable</a>.</p> 677 678</div></div> 679<div class="bottomlang"> 680<p><span>Available Languages: </span><a href="/en/content-negotiation.html" title="English"> en </a> | 681<a href="/fr/content-negotiation.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 682<a href="/ja/content-negotiation.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 683<a href="/ko/content-negotiation.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 684<a href="/tr/content-negotiation.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 685</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 686<script type="text/javascript"><!--//--><![CDATA[//><!-- 687var comments_shortname = 'httpd'; 688var comments_identifier = 'http://httpd.apache.org/docs/2.4/content-negotiation.html'; 689(function(w, d) { 690 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 691 d.write('<div id="comments_thread"><\/div>'); 692 var s = d.createElement('script'); 693 s.type = 'text/javascript'; 694 s.async = true; 695 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 696 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 697 } 698 else { 699 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 700 } 701})(window, document); 702//--><!]]></script></div><div id="footer"> 703<p class="apache">Copyright 2014 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 704<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 705if (typeof(prettyPrint) !== 'undefined') { 706 prettyPrint(); 707} 708//--><!]]></script> 709</body></html>