]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
Fix some typos and inaccuracies and incorrectnesses.
[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 (e.g. a particular directory) onto a particular
43 mime type or handler.
44
45 <P>
46
47 Files can have more than one extension, and the order of the
48 extensions is normally irrelevant. For example, if the file
49 <CODE>welcome.html.fr</CODE> maps onto content type text/html and
50 language French then the file <CODE>welcome.fr.html</CODE> will map
51 onto exactly the same information. The only exception to this is if an
52 extension is given which Apache does not know how to handle. In this
53 case it will "forget" about any information it obtained from
54 extensions to the left of the unknown extension. So, for example, if
55 the extensions fr and html are mapped to the appropriate language and
56 type but extension xxx is not assigned to anything, then the file
57 <CODE>welcome.fr.xxx.html</CODE> will be associated with content-type
58 text/html but <EM>no</EM> language.
59
60 <P>
61
62 Note that changing the type or encoding of a file does not change the
63 value of the <CODE>Last-Modified</CODE> header. Thus, previously cached
64 copies may still be used by a client or proxy, with the previous headers.
65
66 <P>
67
68 Please note that changing a file's type or encoding does not change
69 the value of the <CODE>Last-Modified</CODE> header. Previously cached
70 copies may still be used by a client or proxy.
71
72 <P>
73
74 <H2> Directives</H2>
75 <UL>
76 <LI><A HREF="#addencoding">AddEncoding</A>
77 <LI><A HREF="#addhandler">AddHandler</A>
78 <LI><A HREF="#addlanguage">AddLanguage</A>
79 <LI><A HREF="#addtype">AddType</A>
80 <LI><A HREF="#forcetype">ForceType</A>
81 <LI><A HREF="#sethandler">SetHandler</A>
82 <LI><A HREF="#typesconfig">TypesConfig</A>
83 </UL>
84 <HR>
85
86
87 <H2><A NAME="addencoding">AddEncoding</A></H2>
88 <!--%plaintext &lt;?INDEX {\tt AddEncoding} directive&gt; -->
89 <A
90  HREF="directive-dict.html#Syntax"
91  REL="Help"
92 ><STRONG>Syntax:</STRONG></A> AddEncoding <EM>MIME-enc extension extension...</EM><BR>
93 <A
94  HREF="directive-dict.html#Context"
95  REL="Help"
96 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
97 <A
98  HREF="directive-dict.html#Override"
99  REL="Help"
100 ><STRONG>Override:</STRONG></A> FileInfo<BR>
101 <A
102  HREF="directive-dict.html#Status"
103  REL="Help"
104 ><STRONG>Status:</STRONG></A> Base<BR>
105 <A
106  HREF="directive-dict.html#Module"
107  REL="Help"
108 ><STRONG>Module:</STRONG></A> mod_mime<P>
109
110 The AddEncoding directive adds to the list of filename extensions which
111 filenames may end in for the specified encoding type. <EM>Mime-enc</EM>
112 is the mime encoding to use for documents ending in <EM>extension</EM>.
113 Example:
114 <BLOCKQUOTE><CODE>
115 AddEncoding x-gzip gz<BR>
116 AddEncoding x-compress Z
117 </CODE></BLOCKQUOTE>
118
119 This will cause files ending in .gz to be marked as encoded using the x-gzip
120 encoding, and .Z files to be marked as encoded with x-compress.<P>
121
122 Old clients expect <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>,
123 however the standard dictates that they're equivalent to <CODE>gzip</CODE>
124 and <CODE>compress</CODE> respectively.  Apache does content encoding
125 comparisons by ignoring any leading <CODE>x-</CODE>.  When responding
126 with an encoding Apache will use whatever form (i.e. <CODE>x-foo</CODE>
127 or <CODE>foo</CODE>) the client requested.  If the client didn't
128 specifically request a particular form Apache will use the form given by
129 the <CODE>AddEncoding</CODE> directive.  To make this long story short,
130 you should always use <CODE>x-gzip</CODE> and <CODE>x-compress</CODE>
131 for these two specific encodings.  More recent encodings, such as
132 <CODE>deflate</CODE> should be specified without the <CODE>x-</CODE>.
133
134 <P><HR>
135
136 <H2><A NAME="addhandler">AddHandler</A></H2>
137
138 <A
139  HREF="directive-dict.html#Syntax"
140  REL="Help"
141 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
142 <A
143  HREF="directive-dict.html#Context"
144  REL="Help"
145 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
146 <A
147  HREF="directive-dict.html#Override"
148  REL="Help"
149 ><STRONG>Override:</STRONG></A> FileInfo<BR>
150 <A
151  HREF="directive-dict.html#Status"
152  REL="Help"
153 ><STRONG>Status:</STRONG></A> Base<BR>
154 <A
155  HREF="directive-dict.html#Module"
156  REL="Help"
157 ><STRONG>Module:</STRONG></A> mod_mime<BR>
158 <A
159  HREF="directive-dict.html#Compatibility"
160  REL="Help"
161 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
162 1.1 and later<P>
163
164 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
165 <A HREF="../handler.html">handler</A>
166 <EM>handler-name</EM>. For example, to activate CGI scripts
167 with the file extension "<CODE>.cgi</CODE>", you might use:
168 <PRE>
169     AddHandler cgi-script cgi
170 </PRE>
171
172 <P>Once that has been put into your srm.conf or httpd.conf file, any
173 file ending with "<CODE>.cgi</CODE>" will be treated as a CGI
174 program.</P>
175 <HR>
176
177 <H2><A NAME="addlanguage">AddLanguage</A></H2>
178 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
179 <A
180  HREF="directive-dict.html#Syntax"
181  REL="Help"
182 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>MIME-lang extension extension...</EM><BR>
183 <A
184  HREF="directive-dict.html#Context"
185  REL="Help"
186 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
187 <A
188  HREF="directive-dict.html#Override"
189  REL="Help"
190 ><STRONG>Override:</STRONG></A> FileInfo<BR>
191 <A
192  HREF="directive-dict.html#Status"
193  REL="Help"
194 ><STRONG>Status:</STRONG></A> Base<BR>
195 <A
196  HREF="directive-dict.html#Module"
197  REL="Help"
198 ><STRONG>Module:</STRONG></A> mod_mime<P>
199
200 The AddLanguage directive adds to the list of filename extensions which
201 filenames may end in for the specified content language. <EM>Mime-lang</EM>
202 is the mime language of files with names ending <EM>extension</EM>,
203 after any content encoding extensions have been removed. Example:
204 <BLOCKQUOTE><CODE>
205 AddEncoding x-compress Z<BR>
206 AddLanguage en .en<BR>
207 AddLanguage fr .fr<BR>
208 </CODE></BLOCKQUOTE>
209
210 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a compressed
211 English document. Although the content language is reported to the client,
212 the browser is unlikely to use this information. The AddLanguage directive
213 is more useful for content negotiation, where the server returns one
214 from several documents based on the client's language preference.<P><HR>
215
216 <H2><A NAME="addtype">AddType</A></H2>
217 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
218 <A
219  HREF="directive-dict.html#Syntax"
220  REL="Help"
221 ><STRONG>Syntax:</STRONG></A> AddType <EM>MIME-type extension extension...</EM><BR>
222 <A
223  HREF="directive-dict.html#Context"
224  REL="Help"
225 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
226 <A
227  HREF="directive-dict.html#Override"
228  REL="Help"
229 ><STRONG>Override:</STRONG></A> FileInfo<BR>
230 <A
231  HREF="directive-dict.html#Status"
232  REL="Help"
233 ><STRONG>Status:</STRONG></A> Base<BR>
234 <A
235  HREF="directive-dict.html#Module"
236  REL="Help"
237 ><STRONG>Module:</STRONG></A> mod_mime<P>
238
239 The AddType directive adds to the list of filename extensions which
240 filenames may end in for the specified content type. <EM>Mime-enc</EM>
241 is the mime type to use for documents ending in <EM>extension</EM>.
242 after content-encoding and language extensions have been removed. Example:
243 <BLOCKQUOTE><CODE>
244 AddType image/gif GIF
245 </CODE></BLOCKQUOTE>
246 It is recommended that new mime types be added using the AddType directive
247 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
248 Note that, unlike the NCSA httpd, this directive cannot be used to set the
249 type of particular files.<P><HR>
250
251 <H2><A NAME="forcetype">ForceType</A></H2>
252
253 <A
254  HREF="directive-dict.html#Syntax"
255  REL="Help"
256 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
257 <A
258  HREF="directive-dict.html#Context"
259  REL="Help"
260 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
261 <A
262  HREF="directive-dict.html#Status"
263  REL="Help"
264 ><STRONG>Status:</STRONG></A> Base<BR>
265 <A
266  HREF="directive-dict.html#Module"
267  REL="Help"
268 ><STRONG>Module:</STRONG></A> mod_mime<BR>
269 <A
270  HREF="directive-dict.html#Compatibility"
271  REL="Help"
272 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
273 1.1 and later.<P>
274
275 <P>When placed into an <CODE>.htaccess</CODE> file or a
276 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
277 this directive forces all matching files to be served
278 as the content type given by <EM>media type</EM>. For example, if you
279 had a directory full of GIF files, but did not want to label them all with
280 ".gif", you might want to use:
281 <PRE>
282     ForceType image/gif
283 </PRE>
284 <P>Note that this will override any filename extensions that might determine
285 the media type.</P><HR>
286
287 <H2><A NAME="sethandler">SetHandler</A></H2>
288
289 <A
290  HREF="directive-dict.html#Syntax"
291  REL="Help"
292 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
293 <A
294  HREF="directive-dict.html#Context"
295  REL="Help"
296 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
297 <A
298  HREF="directive-dict.html#Status"
299  REL="Help"
300 ><STRONG>Status:</STRONG></A> Base<BR>
301 <A
302  HREF="directive-dict.html#Module"
303  REL="Help"
304 ><STRONG>Module:</STRONG></A> mod_mime<BR>
305 <A
306  HREF="directive-dict.html#Compatibility"
307  REL="Help"
308 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
309 1.1 and later.<P>
310
311 <P>When placed into an <CODE>.htaccess</CODE> file or a
312 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
313 this directive forces all matching files to be parsed through the
314 <A HREF="../handler.html">handler</A>
315 given by <EM>handler-name</EM>. For example, if you had a
316 directory you wanted to be parsed entirely as imagemap rule files,
317 regardless of extension, you might put the following into an
318 <CODE>.htaccess</CODE> file in that directory:
319 <PRE>
320     SetHandler imap-file
321 </PRE>
322
323 <P>Another example: if you wanted to have the server display a status
324 report whenever a URL of <CODE>http://servername/status</CODE> was
325 called, you might put the following into access.conf:
326 <PRE>
327     &lt;Location /status&gt;
328     SetHandler server-status
329     &lt;/Location&gt;
330 </PRE>
331 <HR>
332
333 <H2><A NAME="typesconfig">TypesConfig</A></H2>
334 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
335 <A
336  HREF="directive-dict.html#Syntax"
337  REL="Help"
338 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
339 <A
340  HREF="directive-dict.html#Default"
341  REL="Help"
342 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/mime.types</CODE><BR>
343 <A
344  HREF="directive-dict.html#Context"
345  REL="Help"
346 ><STRONG>Context:</STRONG></A> server config<BR>
347 <A
348  HREF="directive-dict.html#Status"
349  REL="Help"
350 ><STRONG>Status:</STRONG></A> Base<BR>
351 <A
352  HREF="directive-dict.html#Module"
353  REL="Help"
354 ><STRONG>Module:</STRONG></A> mod_mime<P>
355
356 The TypesConfig directive sets the location of the mime types configuration
357 file. <EM>Filename</EM> is relative to the
358 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
359 mappings from filename extensions to content types; changing this file is not
360 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
361 file contains lines in the format of the arguments to an AddType command:
362 <BLOCKQUOTE><EM>MIME-type extension extension ...</EM></BLOCKQUOTE>
363 The extensions are lower-cased. Blank lines, and lines beginning with a hash
364 character (`#') are ignored.<P>
365
366 <!--#include virtual="footer.html" -->
367 </BODY>
368 </HTML>
369