]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime.html
Some of my semi-regular HTML cleanup (tag ordering, B/I
[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#Status"
148  REL="Help"
149 ><STRONG>Status:</STRONG></A> Base<BR>
150 <A
151  HREF="directive-dict.html#Module"
152  REL="Help"
153 ><STRONG>Module:</STRONG></A> mod_mime<BR>
154 <A
155  HREF="directive-dict.html#Compatibility"
156  REL="Help"
157 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
158 1.1 and later<P>
159
160 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
161 <A HREF="../handler.html">handler</A>
162 <EM>handler-name</EM>. For example, to activate CGI scripts
163 with the file extension "<CODE>.cgi</CODE>", you might use:
164 <PRE>
165     AddHandler cgi-script cgi
166 </PRE>
167
168 <P>Once that has been put into your srm.conf or httpd.conf file, any
169 file ending with "<CODE>.cgi</CODE>" will be treated as a CGI
170 program.</P>
171 <HR>
172
173 <H2><A NAME="addlanguage">AddLanguage</A></H2>
174 <!--%plaintext &lt;?INDEX {\tt AddLanguage} directive&gt; -->
175 <A
176  HREF="directive-dict.html#Syntax"
177  REL="Help"
178 ><STRONG>Syntax:</STRONG></A> AddLanguage <EM>mime-lang extension extension...</EM><BR>
179 <A
180  HREF="directive-dict.html#Context"
181  REL="Help"
182 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
183 <A
184  HREF="directive-dict.html#Override"
185  REL="Help"
186 ><STRONG>Override:</STRONG></A> FileInfo<BR>
187 <A
188  HREF="directive-dict.html#Status"
189  REL="Help"
190 ><STRONG>Status:</STRONG></A> Base<BR>
191 <A
192  HREF="directive-dict.html#Module"
193  REL="Help"
194 ><STRONG>Module:</STRONG></A> mod_mime<P>
195
196 The AddLanguage directive adds to the list of filename extensions which
197 filenames may end in for the specified content language. <EM>Mime-lang</EM>
198 is the mime language of files with names ending <EM>extension</EM>,
199 after any content encoding extensions have been removed. Example:
200 <BLOCKQUOTE><CODE>
201 AddEncoding x-compress Z<BR>
202 AddLanguage en .en<BR>
203 AddLanguage fr .fr<BR>
204 </CODE></BLOCKQUOTE>
205
206 Then the document <CODE>xxxx.en.Z</CODE> will be treated as being a compressed
207 English document. Although the content language is reported to the client,
208 the browser is unlikely to use this information. The AddLanguage directive
209 is more useful for content negotiation, where the server returns one
210 from several documents based on the client's language preference.<P><HR>
211
212 <H2><A NAME="addtype">AddType</A></H2>
213 <!--%plaintext &lt;?INDEX {\tt AddType} directive&gt; -->
214 <A
215  HREF="directive-dict.html#Syntax"
216  REL="Help"
217 ><STRONG>Syntax:</STRONG></A> AddType <EM>mime-type extension extension...</EM><BR>
218 <A
219  HREF="directive-dict.html#Context"
220  REL="Help"
221 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
222 <A
223  HREF="directive-dict.html#Override"
224  REL="Help"
225 ><STRONG>Override:</STRONG></A> FileInfo<BR>
226 <A
227  HREF="directive-dict.html#Status"
228  REL="Help"
229 ><STRONG>Status:</STRONG></A> Base<BR>
230 <A
231  HREF="directive-dict.html#Module"
232  REL="Help"
233 ><STRONG>Module:</STRONG></A> mod_mime<P>
234
235 The AddType directive adds to the list of filename extensions which
236 filenames may end in for the specified content type. <EM>Mime-enc</EM>
237 is the mime type to use for documents ending in <EM>extension</EM>.
238 after content-encoding and language extensions have been removed. Example:
239 <BLOCKQUOTE><CODE>
240 AddType image/gif GIF
241 </CODE></BLOCKQUOTE>
242 It is recommended that new mime types be added using the AddType directive
243 rather than changing the <A HREF="#typesconfig">TypesConfig</A> file.<P>
244 Note that, unlike the NCSA httpd, this directive cannot be used to set the
245 type of particular files.<P><HR>
246
247 <H2><A NAME="forcetype">ForceType</A></H2>
248
249 <A
250  HREF="directive-dict.html#Syntax"
251  REL="Help"
252 ><STRONG>Syntax:</STRONG></A> ForceType <EM>media type</EM><BR>
253 <A
254  HREF="directive-dict.html#Context"
255  REL="Help"
256 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
257 <A
258  HREF="directive-dict.html#Status"
259  REL="Help"
260 ><STRONG>Status:</STRONG></A> Base<BR>
261 <A
262  HREF="directive-dict.html#Module"
263  REL="Help"
264 ><STRONG>Module:</STRONG></A> mod_mime<BR>
265 <A
266  HREF="directive-dict.html#Compatibility"
267  REL="Help"
268 ><STRONG>Compatibility:</STRONG></A> ForceType is only available in Apache
269 1.1 and later.<P>
270
271 <P>When placed into an <CODE>.htaccess</CODE> file or a
272 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
273 this directive forces all matching files to be served
274 as the content type given by <EM>media type</EM>. For example, if you
275 had a directory full of GIF files, but did not want to label them all with
276 ".gif", you might want to use:
277 <PRE>
278     ForceType image/gif
279 </PRE>
280 <P>Note that this will override any filename extensions that might determine
281 the media type.</P><HR>
282
283 <H2><A NAME="sethandler">SetHandler</A></H2>
284
285 <A
286  HREF="directive-dict.html#Syntax"
287  REL="Help"
288 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
289 <A
290  HREF="directive-dict.html#Context"
291  REL="Help"
292 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
293 <A
294  HREF="directive-dict.html#Status"
295  REL="Help"
296 ><STRONG>Status:</STRONG></A> Base<BR>
297 <A
298  HREF="directive-dict.html#Module"
299  REL="Help"
300 ><STRONG>Module:</STRONG></A> mod_mime<BR>
301 <A
302  HREF="directive-dict.html#Compatibility"
303  REL="Help"
304 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
305 1.1 and later.<P>
306
307 <P>When placed into an <CODE>.htaccess</CODE> file or a
308 <CODE>&lt;Directory&gt;</CODE> or <CODE>&lt;Location&gt;</CODE> section,
309 this directive forces all matching files to be parsed through the
310 <A HREF="../handler.html">handler</A>
311 given by <EM>handler-name</EM>. For example, if you had a
312 directory you wanted to be parsed entirely as imagemap rule files,
313 regardless of extension, you might put the following into an
314 <CODE>.htaccess</CODE> file in that directory:
315 <PRE>
316     SetHandler imap-file
317 </PRE>
318
319 <P>Another example: if you wanted to have the server display a status
320 report whenever a URL of <CODE>http://servername/status</CODE> was
321 called, you might put the following into access.conf:
322 <PRE>
323     &lt;Location /status&gt;
324     SetHandler server-status
325     &lt;/Location&gt;
326 </PRE>
327 <HR>
328
329 <H2><A NAME="typesconfig">TypesConfig</A></H2>
330 <!--%plaintext &lt;?INDEX {\tt TypesConfig} directive&gt; -->
331 <A
332  HREF="directive-dict.html#Syntax"
333  REL="Help"
334 ><STRONG>Syntax:</STRONG></A> TypesConfig <EM>filename</EM><BR>
335 <A
336  HREF="directive-dict.html#Default"
337  REL="Help"
338 ><STRONG>Default:</STRONG></A> <CODE>TypesConfig conf/mime.types</CODE><BR>
339 <A
340  HREF="directive-dict.html#Context"
341  REL="Help"
342 ><STRONG>Context:</STRONG></A> server config<BR>
343 <A
344  HREF="directive-dict.html#Status"
345  REL="Help"
346 ><STRONG>Status:</STRONG></A> Base<BR>
347 <A
348  HREF="directive-dict.html#Module"
349  REL="Help"
350 ><STRONG>Module:</STRONG></A> mod_mime<P>
351
352 The TypesConfig directive sets the location of the mime types configuration
353 file. <EM>Filename</EM> is relative to the
354 <A HREF="core.html#serverroot">ServerRoot</A>. This file sets the default list of
355 mappings from filename extensions to content types; changing this file is not
356 recommended. Use the <A HREF="#addtype">AddType</A> directive instead. The
357 file contains lines in the format of the arguments to an AddType command:
358 <BLOCKQUOTE><EM>mime-type extension extension ...</EM></BLOCKQUOTE>
359 The extensions are lower-cased. Blank lines, and lines beginning with a hash
360 character (`#') are ignored.<P>
361
362 <!--#include virtual="footer.html" -->
363 </BODY>
364 </HTML>
365