Home Account

Make apache2 handle epub downloads

2014-01-06 15:54 dennis iversen

Tags: apache2

After playing around with the excellent pandoc, I decided to try and make epub books and pdf files from markdown articles. Pdf worked fine, but on e.g. android it was not possible to download the epub files. It just said it could not recognize the file format.

I checked the gutenberg project and examined the headers, which gave the following result:

    Array
    (
        [0] => HTTP/1.1 200 OK
        [1] => Server: Apache
        [2] => X-Rate-Limiter: ratelimiter2.php
        [3] => Set-Cookie: session_id=8b0c13d8276098a7158afcfb13cac0d21d2b30f5; Domain=.gutenberg.org; expires=Mon, 06 Jan 2014 13:19:06 GMT; Path=/
        [4] => X-Frame-Options: sameorigin
        [5] => X-Connection: Close
        [6] => Content-Type: application/epub+zip
        [7] => Content-Length: 285830
        [8] => X-Powered-By: 3
        [9] => Date: Mon, 06 Jan 2014 12:49:06 GMT
        [10] => X-Varnish: 835261757
        [11] => Age: 0
        [12] => Via: 1.1 varnish
        [13] => Connection: close
    )

What should be noticed is really just this header:

 Content-Type: application/epub+zip

To fix the missing downloads of epub books you will need to enable the mod_headers module, and then add the following lines to your hosts configuration:

<IfModule mod_headers.c>
    <FilesMatch "\.(epub)$">
        ForceType application/epub+zip
        Header set Content-Disposition "attachment"
        Allow from all
    </FilesMatch>
</IfModule>

Then download of epubs will work from your android device.

You should be able to the same trick for .mobi files (kindle e-reader files). Add the following to your apache2 configuration file:

<IfModule mod_headers.c>
    <FilesMatch "\.(mobi)$">
        ForceType application/mobi+zip
        Header set Content-Disposition "attachment"
        Allow from all
    </FilesMatch>
</IfModule>

This page has been requested 4735 times