No Gravatar

This post is a quick tutorial about adding support for mobile MIME types in the Apache web server using .htaccess configuration. See this related page for comprehensive list of mobile MIME types for XHTML-MP, WML and binary files.

The Apache web server uses .htaccess files to provide a lightweight method of updating and overriding web server configuration inside a directory. A .htaccess file is an ASCII file containing plaintext configuration directives read by Apache when serving files in the directory. On UNIX servers, .htaccess is a hidden file by default, so be sure to use the shell command ‘ls -la” to view hidden and visible files to check whether a directory contains the file.

Apache extension modules specify configuration directives (or statements) found in .htaccess files. The mod_mime extension defines the AddType directive that manages associating MIME types (or content types) with file extensions.

The AddType directive uses this text format to specify the MIME type and a space-delimited list of associated file extensions:

AddType <MIME type> <file extension> [<file extension>] …

When a HTTP request is made for a file with the configured file extension, Apache serves the content and sends the MIME type as the value of the Content-Type HTTP response header.

[ad name=”ltmw-banner-468×60″]

Here is an example of using AddType directives .htaccess files to introduce new content types for mobile markup mapped to file extensions. One directive is allowed per line of the configuration file:


# Add Mobile MIME types for xhtml, wml, wbmp and wmls file extensions
AddType application/vnd.wap.xhtml+xml .xhtml
AddType text/vnd.wap.wml .wml
AddType image/vnd.wap.wbmp .wbmp
AddType text/vnd.wap.wmlscript .wmls

A single AddType directive can associate multiple file extensions with the same MIME type. Here is an example that associates xhtml and xhtm file extensions with the application/vnd.wap.xhtml+xml content type:


AddType application/vnd.wap.xhtml+xml .xhtml .xhtm

[ad name=”ltmw-banner-468×60″]

The configuration in .htaccess files affects the directory in which the file is placed and all subdirectories. But, there is no inheritance for directives in .htaccess configuration. The .htaccess file nearest to the target web document is the configuration file used to serve the document. Make sure to upload your .htaccess file into the appropriate web server location.

There are performance implications when using multiple .htaccess files across a website, especially if a single Apache instance hosts multiple domains. Because configuration is distributed across the file system, Apache must inspect the directory hierachy to determine which .htaccess file applies for a HTTP request. Think carefully when creating multiple .htaccess configuration files and centralize wherever possible.

Also, the .htaccess file must be readable by the UNIX user running the Apache httpd process.

VN:F [1.9.22_1171]
Rating: 5.0/5 (2 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Adding Mobile MIME Types in Apache .htaccess Files, 5.0 out of 5 based on 2 ratings