Apache2 serves MS Publisher file, MS Edge/IE opens it as text

I have a Microsoft Publisher file. It works just fine. I have it on Linux, in /var/www/html.

Apache2 is running with the default configuration.

I try to open it from Windows in MS Edge and IE. It displays as text (broken or no response encoding?) instead of downloading. I want to trigger Protected View for testing purposes. Why won't MS Edge or IE download the file instead of interpreting the binary file contents as HTML?


Solution 1:

The file extension .pub is ambiguous, as it can refer to many MIME types (none of them being IANA assigned media types):

  • SSH public keys: ASCII armored text files, text/plain
  • Microsoft Publisher documents, application/x-mspublisher
  • Corel Ventura Publisher Publication, application/x-pub

By default, Apache uses /etc/mime.types for adding the correct Content-Type header. As there's no specified value for .pub, there's no Content-Type, and the browser is left to guess.

You could add a specific MIME type:

application/x-mspublisher                       pub

Or if you would like to force downloada, you could add the extension to:

application/octet-stream                        bin deploy msu msp pub

In addition, it's possible to add Content-Type for individual files with the ForceType Directive:

<Files "Microsoft.pub">
    ForceType application/x-mspublisher
</Files>

<Files "Corel.pub">
    ForceType application/x-pub
</Files>

<Files "Download.pub">
    ForceType application/octet-stream
</Files>

<Files "SSH-public-key.pub">
    ForceType text/plain
</Files>

# Default for all other .pub files
<Files ~ "\.pub$">
    ForceType text/plain
</Files>