]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
Point out that for multiple AddLanguage directives with the
[apache] / docs / manual / mod / mod_mime.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Apache module mod_mime</TITLE>
5 </HEAD>
6
7 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
8 <BODY
9  BGCOLOR="#FFFFFF"
10  TEXT="#000000"
11  LINK="#0000FF"
12  VLINK="#000080"
13  ALINK="#FF0000"
14 >
15 <!--#include virtual="header.html" -->
16 <H1 ALIGN="CENTER">Module mod_mime</H1>
17
18 This module is contained in the <CODE>mod_mime.c</CODE> file, and is
19 compiled in by default. It provides for determining the types of files
20 from the filename.
21
22 <H2>Summary</H2>
23
24 This module is used to determine various bits of "meta information"
25 about documents. This information relates to the content of the
26 document and is returned to the browser or used in content-negotiation
27 within the server. In addition, a "handler" can be set for a document,
28 which determines how the document will be processed within the server.
29
30 <P>
31
32 The directives <A HREF="#addencoding">AddEncoding</A>, <A
33 HREF="#addhandler">AddHandler</A>, <A
34 HREF="#addlanguage">AddLanguage</A> and <A HREF="#addtype">AddType</A>
35 are all used to map file extensions onto the meta-information for that
36 file.  Respectively they set the content-encoding, handler,
37 content-language and MIME-type (content-type) of documents.  The
38 directive <A HREF="#typesconfig">TypesConfig</A> is used to specify a
39 file which also maps extensions onto MIME types. The directives <A
40 HREF="#forcetype">ForceType</A> and <A
41 HREF="#sethandler">SetHandler</A> are used to associated all the files
42 in a given location (<EM>e.g.</EM>, a particular directory) onto a particular
43 MIME type or handler.
44
45 <P>
46
47 Note that changing the type or encoding of a file does not change the
48 value of the <CODE>Last-Modified</CODE> header. Thus, previously cached
49 copies may still be used by a client or proxy, with the previous headers.
50
51 <H2><A NAME="multipleext">Files with Multiple Extensions</A></H2>
52
53 Files can have more than one extension, and the order of the
54 extensions is <EM>normally</EM> irrelevant. For example, if the file
55 <CODE>welcome.html.fr</CODE> maps onto content type text/html and
56 language French then the file <CODE>welcome.fr.html</CODE> will map
57 onto exactly the same information. The only exception to this is if an
58 extension is given which Apache does not know how to handle. In this
59 case it will "forget" about any information it obtained from
60 extensions to the left of the unknown extension. So, for example, if
61 the extensions fr and html are mapped to the appropriate language and
62 type but extension xxx is not assigned to anything, then the file
63 <CODE>welcome.fr.xxx.html</CODE> will be associated with content-type
64 text/html but <EM>no</EM> language.
65
66 <P>
67
68 If more than one extension is given which maps onto the same type of
69 meta-information, then the one to the right will be used. For example,
70 if ".gif" maps to the MIME-type image/gif and ".html" maps to the
71 MIME-type text/html, then the file <CODE>welcome.gif.html</CODE> will
72 be associated with the MIME-type "text/html".
73
74 <P>
75
76 Care should be taken when a file with multiple extensions gets
77 associated with both a MIME-type and a handler. This will usually
78 result in the request being by the module associated with the
79 handler. For example, if the <CODE>.imap</CODE> extension is mapped to
80 the handler "imap-file" (from mod_imap) and the <CODE>.html</CODE>
81 extension is mapped to the MIME-type "text/html", then the file
82 <CODE>world.imap.html</CODE> will be associated with both the
83 "imap-file" handler and "text/html" MIME-type. When it is processed,
84 the "imap-file" handler will be used, and so it will be treated as a
85 mod_imap imagemap file.
86
87 <H2>Directives</H2>
88 <UL>
89 <LI><A HREF="#addencoding">AddEncoding</A>
90 <LI><A HREF="#addhandler">AddHandler</A>
91 <LI><A HREF="#addlanguage">AddLanguage</A>
92 <LI><A HREF="#addtype">AddType</A>
93 <LI><A HREF="#defaultlanguage">DefaultLanguage</A>
94 <LI><A HREF="#forcetype">ForceType</A>
95 <LI><A HREF="#removehandler">RemoveHandler</A>
96 <LI><A HREF="#sethandler">SetHandler</A>
97 <LI><A HREF="#typesconfig">TypesConfig</A>
98 </UL>
99 <HR>
100
101
102 <H2><A NAME="addencoding">AddEncoding</A></H2>
103 <!--%plaintext &lt;?INDEX {\tt AddEncoding} directive&gt; -->
104 <A
105  HREF="directive-dict.html#Syntax"
106  REL="Help"
107 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
108 <A
109  HREF="directive-dict.html#Context"
110  REL="Help"
111 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
112 <A
113  HREF="directive-dict.html#Override"
114  REL="Help"
115 ><STRONG>Override:</STRONG></A> FileInfo<BR>
116 <A
117  HREF="directive-dict.html#Status"
118  REL="Help"
119 ><STRONG>Status:</STRONG></A> Base<BR>
120 <A
121  HREF="directive-dict.html#Module"
122  REL="Help"
123 ><STRONG>Module:</STRONG></A> mod_mime<P>
124
125 The AddEncoding directive maps the given filename extensions to the
126 specified encoding type. <EM>MIME-enc</EM> is the MIME encoding to use
127 for documents containing the <EM>extension</EM>. This mapping is added
128 to any already in force, overriding any mappings that already exist
129 for the same <EM>extension</EM>.
130
131 Example:
132 <BLOCKQUOTE><CODE> AddEncoding x-gzip gz<BR> AddEncoding x-compress Z
133 </CODE></BLOCKQUOTE>
134
135 This will cause filenames containing the .gz extension to be marked as
136 encoded using the x-gzip encoding, and filenames containing the .Z
137 extension to be marked as encoded with x-compress.<P>
138
139 Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
140 however the standard dictates that they're equivalent to <CODE>gzip</CODE>
141 and <CODE>compress</CODE> respectively.  Apache does content encoding
142 comparisons by ignoring any leading <CODE>x-</CODE>.  When responding
143 with an encoding Apache will use whatever form (<EM>i.e.</EM>, <CODE>x-foo</CODE>
144 or <CODE>foo</CODE>) the client requested.  If the client didn't
145 specifically request a particular form Apache will use the form given by
146 the <CODE>AddEncoding</CODE> directive.  To make this long story short,
147 you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
148 for these two specific encodings.  More recent encodings, such as
149 <CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
150
151 <P>
152
153 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
154 multiple extensions</A>
155
156 <P><HR>
157
158 <H2><A NAME="addhandler">AddHandler</A></H2>
159
160 <A
161  HREF="directive-dict.html#Syntax"
162  REL="Help"
163 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
164 <A
165  HREF="directive-dict.html#Context"
166  REL="Help"
167 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
168 <A
169  HREF="directive-dict.html#Override"
170  REL="Help"
171 ><STRONG>Override:</STRONG></A> FileInfo<BR>
172 <A
173  HREF="directive-dict.html#Status"
174  REL="Help"
175 ><STRONG>Status:</STRONG></A> Base<BR>
176 <A
177  HREF="directive-dict.html#Module"
178  REL="Help"
179 ><STRONG>Module:</STRONG></A> mod_mime<BR>
180 <A
181  HREF="directive-dict.html#Compatibility"
182  REL="Help"
183 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
184 1.1 and later<P>
185
186 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
187 <A HREF="../handler.html">handler</A> <EM>handler-name</EM>.  This
188 mapping is added to any already in force, overriding any mappings that
189 already exist for the same <EM>extension</EM>.
190
191 For example, to activate CGI scripts
192 with the file extension "<CODE>.cgi</CODE>", you might use:
193 <PRE>
194     AddHandler cgi-script cgi
195 </PRE>
196
197 <P>Once that has been put into your srm.conf or httpd.conf file, any
198 file containing the "<CODE>.cgi</CODE>" extension will be treated as a
199 CGI program.</P> 
200
201 <P>
202
203 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
204 multiple extensions</A>
205
206 <HR>
207
208 <H2><A NAME="addlanguage">AddLanguage</A></H2>
209 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
210 <A
211  HREF="directive-dict.html#Syntax"
212  REL="Help"
213 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
214 <A
215  HREF="directive-dict.html#Context"
216  REL="Help"
217 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
218 <A
219  HREF="directive-dict.html#Override"
220  REL="Help"
221 ><STRONG>Override:</STRONG></A> FileInfo<BR>
222 <A
223  HREF="directive-dict.html#Status"
224  REL="Help"
225 ><STRONG>Status:</STRONG></A> Base<BR>
226 <A
227  HREF="directive-dict.html#Module"
228  REL="Help"
229 ><STRONG>Module:</STRONG></A> mod_mime
230
231 <P>
232 The AddLanguage directive maps the given filename extensions to the
233 specified content language. <EM>MIME-lang</EM> is the MIME language of
234 filenames containing <EM>extension</EM>.  This mapping is added to any
235 already in force, overriding any mappings that already exist for the
236 same <EM>extension</EM>.
237 </P>
238 <P>
239 Example: <BLOCKQUOTE><CODE>
240 AddEncoding x-compress Z<BR> AddLanguage en .en<BR> AddLanguage fr
241 .fr<BR> </CODE></BLOCKQUOTE>
242 </P>
243 <P>
244 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a
245 compressed English document (as will the document
246 <CODE>xxxx.Z.en</CODE>). Although the content language is reported to
247 the client, the browser is unlikely to use this information. The
248 AddLanguage directive is more useful for
249 <A HREF="../content-negotiation.html">content negotiation</A>, where
250 the server returns one from several documents based on the client's
251 language preference.
252 </P>
253 <P>
254 If multiple language assignments are made for the same extension,
255 the last one encountered is the one that is used.  That is, for the
256 case of:
257 </P>
258 <PRE>
259     AddLanguage en .en
260     AddLanguage en-uk .en
261     AddLanguage en-us .en
262 </PRE>
263 <P>
264 documents with the extension "<CODE>.en</CODE>" would be treated as
265 being "<CODE>en-us</CODE>".
266 </P>
267 <P>
268 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
269 multiple extensions</A>
270 <BR>
271 <STRONG>See also</STRONG>: <A
272 HREF="./mod_negotiation.html">mod_negotiation</A>
273 </P>
274
275 <HR>
276
277 <H2><A NAME="addtype">AddType</A></H2>
278 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
279 <A
280  HREF="directive-dict.html#Syntax"
281  REL="Help"
282 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
283 <A
284  HREF="directive-dict.html#Context"
285  REL="Help"
286 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
287 <A
288  HREF="directive-dict.html#Override"
289  REL="Help"
290 ><STRONG>Override:</STRONG></A> FileInfo<BR>
291 <A
292  HREF="directive-dict.html#Status"
293  REL="Help"
294 ><STRONG>Status:</STRONG></A> Base<BR>
295 <A
296  HREF="directive-dict.html#Module"
297  REL="Help"
298 ><STRONG>Module:</STRONG></A> mod_mime<P>
299
300 The AddType directive maps the given filename extensions onto the
301 specified content type. <EM>MIME-enc</EM> is the MIME type to use for
302 filenames containing <EM>extension</EM>.  This mapping is added to any
303 already in force, overriding any mappings that already exist for the
304 same <EM>extension</EM>. This directive can be used to add mappings
305 not listed in the MIME types file (see the <CODE><A
306 HREF="#typesconfig">TypesConfig</A></CODE> directive).
307
308 Example:
309 <BLOCKQUOTE><CODE>
310 AddType image/gif GIF
311 </CODE></BLOCKQUOTE>
312 It is recommended that new MIME types be added using the AddType directive
313 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
314 Note that, unlike the NCSA httpd, this directive cannot be used to set the
315 type of particular files.<P>
316
317 <P>
318
319 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
320 multiple extensions</A>
321
322 <HR>
323
324 <H2><A NAME="defaultlanguage">DefaultLanguage</A></H2>
325 <!--%plaintext &lt;?INDEX {\tt DefaultLanguage} directive&gt; -->
326 <A
327  HREF="directive-dict.html#Syntax"
328  REL="Help"
329 ><STRONG>Syntax:</STRONG></A> DefaultLanguage <EM>MIME-lang</EM><BR>
330 <A
331  HREF="directive-dict.html#Context"
332  REL="Help"
333 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
334 <A
335  HREF="directive-dict.html#Override"
336  REL="Help"
337 ><STRONG>Override:</STRONG></A> FileInfo<BR>
338 <A
339  HREF="directive-dict.html#Status"
340  REL="Help"
341 ><STRONG>Status:</STRONG></A> Base<BR>
342 <A
343  HREF="directive-dict.html#Module"
344  REL="Help"
345 ><STRONG>Module:</STRONG></A> mod_mime<P>
346
347 The DefaultLanguage directive tells Apache that all files in the
348 directive's scope (<EM>e.g.</EM>, all files covered by the current
349 <CODE>&lt;Directory&gt;</CODE> container) that don't have an explicit
350 language extension (such as <SAMP>.fr</SAMP> or <SAMP>.de</SAMP> as
351 configured by <SAMP>AddLanguage</SAMP>) should be considered to be in
352 the specified <EM>MIME-lang</EM> language.  This allows entire
353 directories to be marked as containing Dutch content, for instance,
354 without having to rename each file. Note that unlike using extensions
355 to specify languages, <SAMP>DefaultLanguage</SAMP> can only specify a
356 single language.
357
358 <P>
359
360 If no <SAMP>DefaultLanguage</SAMP> directive is in force, and a file
361 does not have any language extensions as configured by
362 <SAMP>AddLanguage</SAMP>, then that file will be considered to have no
363 language attribute.
364
365 <P>
366
367 <STRONG>See also</STRONG>: <A
368 HREF="./mod_negotiation.html">mod_negotiation</A>
369 <BR>
370 <STRONG>See also</STRONG>: <A HREF="#multipleext">Files with
371 multiple extensions</A>
372
373 <HR>
374
375 <H2><A NAME="forcetype">ForceType</A></H2>
376
377 <A
378  HREF="directive-dict.html#Syntax"
379  REL="Help"
380 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
381 <A
382  HREF="directive-dict.html#Context"
383  REL="Help"
384 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
385 <A
386  HREF="directive-dict.html#Status"
387  REL="Help"
388 ><STRONG>Status:</STRONG></A> Base<BR>
389 <A
390  HREF="directive-dict.html#Module"
391  REL="Help"
392 ><STRONG>Module:</STRONG></A> mod_mime<BR>
393 <A
394  HREF="directive-dict.html#Compatibility"
395  REL="Help"
396 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
397 1.1 and later.<P>
398
399 <P>When placed into an <CODE>.htaccess</CODE> file or a
400 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
401 this directive forces all matching files to be served
402 as the content type given by <EM>media type</EM>. For example, if you
403 had a directory full of GIF files, but did not want to label them all with
404 ".gif", you might want to use:
405 <PRE>
406     ForceType image/gif
407 </PRE>
408 <P>Note that this will override any filename extensions that might determine
409 the media type.</P><HR>
410
411 <H2><A NAME="removehandler">RemoveHandler</A></H2>
412
413 <A
414  HREF="directive-dict.html#Syntax"
415  REL="Help"
416 ><STRONG>Syntax:</STRONG></A> RemoveHandler <EM>extension extension...</EM><BR>
417 <A
418  HREF="directive-dict.html#Context"
419  REL="Help"
420 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
421 <A
422  HREF="directive-dict.html#Status"
423  REL="Help"
424 ><STRONG>Status:</STRONG></A> Base<BR>
425 <A
426  HREF="directive-dict.html#Module"
427  REL="Help"
428 ><STRONG>Module:</STRONG></A> mod_mime<BR>
429 <A
430  HREF="directive-dict.html#Compatibility"
431  REL="Help"
432 ><STRONG>Compatibility:</STRONG></A> RemoveHandler is only available in Apache
433 1.3.4 and later.<P>
434
435 <P>
436 The <SAMP>RemoveHandler</SAMP> directive removes any
437 handler associations for files with the given extensions.
438 This allows <CODE>.htaccess</CODE> files in subdirectories to undo
439 any associations inherited from parent directories or the server
440 config files.  An example of its use might be:
441 </P>
442 <DL>
443  <DT><CODE>/foo/.htaccess:</CODE></DT>
444  <DD><CODE>AddHandler server-parsed .html</CODE></DD>
445  <DT><CODE>/foo/bar/.htaccess:</CODE></DT>
446  <DD><CODE>RemoveHandler .html</CODE></DD>
447 </DL>
448 <P>
449 This has the effect of returning <SAMP>.html</SAMP> files in the
450 <SAMP>/foo/bar</SAMP> directory to being treated as normal
451 files, rather than as candidates for parsing (see the
452 <A HREF="mod_include.html"><SAMP>mod_include</SAMP></A> module).
453 </P>
454 <HR>
455
456 <H2><A NAME="sethandler">SetHandler</A></H2>
457
458 <A
459  HREF="directive-dict.html#Syntax"
460  REL="Help"
461 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
462 <A
463  HREF="directive-dict.html#Context"
464  REL="Help"
465 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
466 <A
467  HREF="directive-dict.html#Status"
468  REL="Help"
469 ><STRONG>Status:</STRONG></A> Base<BR>
470 <A
471  HREF="directive-dict.html#Module"
472  REL="Help"
473 ><STRONG>Module:</STRONG></A> mod_mime<BR>
474 <A
475  HREF="directive-dict.html#Compatibility"
476  REL="Help"
477 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
478 1.1 and later.<P>
479
480 <P>When placed into an <CODE>.htaccess</CODE> file or a
481 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
482 this directive forces all matching files to be parsed through the
483 <A HREF="../handler.html">handler</A>
484 given by <EM>handler-name</EM>. For example, if you had a
485 directory you wanted to be parsed entirely as imagemap rule files,
486 regardless of extension, you might put the following into an
487 <CODE>.htaccess</CODE> file in that directory:
488 <PRE>
489     SetHandler imap-file
490 </PRE>
491
492 <P>Another example: if you wanted to have the server display a status
493 report whenever a URL of <CODE>http://servername/status</CODE> was
494 called, you might put the following into access.conf:
495 <PRE>
496     &lt;Location /status&gt;
497     SetHandler server-status
498     &lt;/Location&gt;
499 </PRE>
500 <HR>
501
502 <H2><A NAME="typesconfig">TypesConfig</A></H2>
503 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
504 <A
505  HREF="directive-dict.html#Syntax"
506  REL="Help"
507 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
508 <A
509  HREF="directive-dict.html#Default"
510  REL="Help"
511 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/MIME.types</CODE><BR>
512 <A
513  HREF="directive-dict.html#Context"
514  REL="Help"
515 ><STRONG>Context:</STRONG></A> server config<BR>
516 <A
517  HREF="directive-dict.html#Status"
518  REL="Help"
519 ><STRONG>Status:</STRONG></A> Base<BR>
520 <A
521  HREF="directive-dict.html#Module"
522  REL="Help"
523 ><STRONG>Module:</STRONG></A> mod_mime<P>
524
525 The TypesConfig directive sets the location of the MIME types configuration
526 file. <EM>Filename</EM> is relative to the
527 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
528 mappings from filename extensions to content types; changing this file is not
529 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
530 file contains lines in the format of the arguments to an AddType command:
531 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
532 The extensions are lower-cased. Blank lines, and lines beginning with a hash
533 character (`#') are ignored.<P>
534
535 <!--#include virtual="footer.html" -->
536 </BODY>
537 </HTML>
538