mod_mime_magic.html revision 2eaf662cbc81e823e8d9aeb8d54e69e63032493e
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <meta name="generator" content="HTML Tidy, see www.w3.org" />
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <img src="/images/sub.gif" alt="[APACHE DOCUMENTATION]" />
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <p>This module provides for determining the MIME type of a file
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen by looking at a few bytes of its contents.</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen rel="Help"><strong>Status:</strong></a> Extension<br />
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen rel="Help"><strong>Module Identifier:</strong></a>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen mime_magic_module</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <p>This module determines the MIME type of files in the same
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen way the Unix file(1) command works: it looks at the first few
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen bytes of the file. It is intended as a "second line of defense"
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen for cases that <a href="mod_mime.html">mod_mime</a> can't
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen resolve. To assure that mod_mime gets first try at determining
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen a file's MIME type, be sure to list mod_mime_magic
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <strong>before</strong> mod_mime in the configuration.</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <p>This module is derived from a free version of the
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <code>file(1)</code> command for Unix, which uses "magic
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen numbers" and other hints from a file's contents to figure out
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen what the contents are. This module is active only if the magic
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen file is specified by the <a
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen href="#mimemagicfile"><code>MimeMagicFile</code></a>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen directive.</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <li><a href="#mimemagicfile">MimeMagicFile</a></li>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <p>The contents of the file are plain ASCII text in 4-5
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen columns. Blank lines are allowed but ignored. Commented lines
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen use a hash mark "#". The remaining lines are parsed for the
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen following columns:</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen ">" indicates a dependency upon the previous non-">"
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen type of data to match
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <td>long integer date (seconds since Unix
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen <p>For example, the following magic file lines would recognize
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen some audio formats.</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen Or these would recognize the difference between "*.doc" files
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen containing Microsoft Word or FrameMaker documents. (These are
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen incompatible file formats which use the same file suffix.)
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen0 string \<MakerDictionary application/x-frame
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen0 string \<MakerScreenFon application/x-frame
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen0 string \320\317\021\340\241\261 application/msword
9934242994745cb810b290e3127f6a75d89d2177Timo Sirainen An optional MIME encoding can be included as a fifth column.
9934242994745cb810b290e3127f6a75d89d2177Timo Sirainen For example, this can recognize gzipped files and set the
9934242994745cb810b290e3127f6a75d89d2177Timo Sirainen encoding for them.
348202a977aea7bf72aa0fb62ccfdd6dcc41cb03Timo Sirainen# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
348202a977aea7bf72aa0fb62ccfdd6dcc41cb03Timo Sirainen0 string \037\213 application/octet-stream x-gzip
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen This module is not for every system. If your system is barely
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen keeping up with its load or if you're performing a web server
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen benchmark, you may not want to enable this because the
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen processing is not free.
9e50448ea2513fe4edee9e14ddcb9bb031823f0fTimo Sirainen <p>However, an effort was made to improve the performance of
348202a977aea7bf72aa0fb62ccfdd6dcc41cb03Timo Sirainen the original file(1) code to make it fit in a busy web server.
348202a977aea7bf72aa0fb62ccfdd6dcc41cb03Timo Sirainen It was designed for a server where there are thousands of users
348202a977aea7bf72aa0fb62ccfdd6dcc41cb03Timo Sirainen who publish their own documents. This is probably very common
1728ff34ee03de825ad3aeed67d19f8ae140ee2eTimo Sirainen on intranets. Many times, it's helpful if the server can make
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen more intelligent decisions about a file's contents than the
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen file name allows ...even if just to reduce the "why doesn't my
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen page work" calls when users improperly name their own files.
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen You have to decide if the extra work suits your
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen environment.</p>
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen <p>When compiling an Apache server, this module should be at or
cea31bf9e588436588e06625c741c0a87de673f1Timo Sirainen near the top of the list of modules in the Configuration file.
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen The modules are listed in increasing priority so that will mean
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen this one is used only as a last resort, just like it was
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen designed to.</p>
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen The following notes apply to the mod_mime_magic module and are
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen included here for compliance with contributors' copyright
dca6d617a23e3f93af3b8df59acb46478179fe55Timo Sirainen restrictions that require their acknowledgment.
* originally posted to comp.sources.unix. Copyright info for that program