Epub Fix

Back to HOWTOS

Date Created: 8/15/2023

Last Update: 8/15/2023

I added the pdfs and epubs for my fanfiction to my new website. At first there was a problem with the epubs. The browser was trying to open them as plaintext files, which they are not, so they just looked like a bunch of garbage symbols on the screen.

The pdf files opened fine, probably because browsers can open them natively.

I figured out the issue with the epubs, though. I had suspected that it was being caused because epubs are not a typical web file, and it turned out I was correct about that. The browser uses something called MIME types to determine how to handle files. For any non-standard file type, you need to create an .htaccess file and tell it the MIME type. So in the root directory of my website, I added the .htaccess file with the following line:

AddType application/epub+zip epub

I'll have to do this if I add any other non-standard MIME types to my site, which I may very well want to do. Being able to add different types of media is one of the advantages of having a personal website.

The general format for the MIME types is:

AddType type/subtype extension

There's a list of commonly used MIME types for the web here:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

After that I had to clear my cache in Firefox with Settings->Delete Browsing Data and selected 'Browing History and Site Data' and 'Cached Images and Files' to clear the site from my browser and make sure it fetched the .htaccess data instead of using what it had already loaded in. And then it worked!

I might not have had to clear out both of those settings but I just wanted to make sure the site was completely cleared out before proceeding.