MIMEタイプの追加(AddType)
Webサーバで公開されているファイルはテキストファイルやHTMLファイルだけではありません。画像や動画など様々なファイルを扱います。クライアントからリクエストがあったファイルに対して、WWWサーバはファイルの内容を返すと同時にそのファイルがどのような種類のファイルなのかを合わせてクライアントへ返します。その結果、クライアント側は取得したデータを適切な表示方法で扱うことが出来るようになります。
基本となるMIMEタイプと拡張子の組み合わせはデフォルトでは「mime.types」ファイルで登録されています。このファイル名及び設置ディレクトリは「TypesConfig」で設定されています。
それでは「httpd.conf」ファイルで「TypesConfig」で検索してみてください。363行目付近に次の記述が見つかります。
<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig conf/mime.types
</IfModule>
相対パスで指定されていますので「ServerRoot」からの相対パスとなっています。その為、実際のファイルは「D:¥Apache Group¥Apache2.2¥conf¥mime.types」となります。
「mime.types」はテキストファイルですのでテキストエディタで開いて見てください。一部を抜粋すると次のようになります。
# MIME type Extensions text/csv csv text/directory text/dns text/enriched text/html html htm text/parityfec text/plain txt text conf def list log in text/prs.fallenstein.rst text/prs.lines.tag dsc text/red text/rfc822-headers text/richtext rtx
MIMEタイプと対応する拡張子が登録されています。例えば「.html」や「.htm」の拡張子が付いたファイルはMIMEタイプが「text/html」となり、「.txt」や「.log」の拡張子が付いたファイルはMIMEタイプは「text/plain」となります。
MIMEタイプを追加する
既に登録されている拡張子の他に、別の拡張子に対するMIMEタイプを追加で登録することが出来ます。その場合は「mime.types」に追加で記述する代わりに「httpd.conf」ファイル内で「AddType」を使って記述することが推奨されています。
AddType MIMEタイプ 拡張子
MIMEタイプと拡張子をセットで指定します。
それでは「httpd.conf」ファイルで「AddType」で検索してみてください。363行目付近に次の記述が見つかります。
<IfModule mime_module>
#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
例としてPHPのファイルである「.php」及び「.phps」に対するMIMEタイプの設定を行うには次のように記述します。
<IfModule mime_module>
#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
( Written by Tatsuo Ikura )

AdminWeb