Educational ICT Virtualisation Specialist

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)8456 446 800 / +44 (0)1223 359900
E: enquiries@precedence.co.uk
Webserver-mimetypes

Jump To: Support > KB > NetManager > Webserver > mimetypes

Customising MIME types

Data returned by a web-server needs to declare what type it is. This is known as its MIME type and corresponds to the Content-Type: HTTP header. MIME types look like family/detail where family is the general class such as text or image and detail provides information about the exact type. For example, HTML is text/html and JPEG files are image/jpeg. The web-server usually determines the MIME type from the filename (e.g. .jpg files are image/jpeg). Most common files types are recognised, but any files that are not known will be sent as text/plain which means the web-browser may just try to display the raw contexnts. You can add your own MIME tpes by editing the /etc/netmanager/mime.types file. For example:
application/epub+zip .ibooks
image/jpeg .elephant

The first line will ensure that .ibooks files are sent as the right type.

The second line will allow you to rename your .jpg files to .elephant and still get them to be recognised as images (not very useful, I know).

Using AddType in .htaccess files

As well as defining MIME types centrally in the web-server configuration using the /etc/netmanager/mime.types file, you can set then on a per-directory basis by creating a .htaccess file containing the same lines by prefixed with AddType:
AddType application/epub+zip .ibooks
AddType image/jpeg .elephant

Demonstration

Before altering mime.types:
% curl --head http://webserver.name.here/photo.elephant
HTTP/1.1 200 OK
Date: Wed, 16 Sep 2015 09:51:10 GMT
Server: Apache
Last-Modified: Wed, 16 Sep 2015 09:39:14 GMT
ETag: "50e4d-0-51fda124f05bf"
Accept-Ranges: bytes
X-Clacks-Overhead: GNU Terry Pratchett
Content-Type: text/plain

Afterwards:
% curl --head http://webserver.name.here/photo.elephant
HTTP/1.1 200 OK
Date: Wed, 16 Sep 2015 09:54:28 GMT
Server: Apache
Last-Modified: Wed, 16 Sep 2015 09:39:14 GMT
ETag: "50e4d-0-51fda124f05bf"
Accept-Ranges: bytes
X-Clacks-Overhead: GNU Terry Pratchett
Content-Type: image/jpeg

© Copyright Precedence Technologies 1999-2024
Page last modified on September 16, 2015, at 10:57 AM by sborrill