Backport mime-type parsing fixes

Backport fixes to mime type parsing which are causing `ActiveRecord::MissingTemplate` exceptions when we're being crawled by googlebot and others.

@tamird @JackDanger @ecin