How to Fix DOCX/XLSX/PPTX Files Downloading as ZIP on Apache Server: MIME Type Configuration Guide


1 views

When Office 2007+ files (DOCX/XLSX/PPTX) get served from your Apache server, some browsers misinterpret them as ZIP archives because:

  • These formats actually use ZIP compression internally
  • Missing or incorrect MIME type declarations in server config
  • Browser heuristics overriding declared content types

Add these MIME types to your Apache configuration (either in .htaccess or main config):


# Office 2007+ MIME types
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx

For Ubuntu servers, you might also need to update the global MIME types:


sudo nano /etc/mime.types

# Add these lines if not present:
application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet         xlsx
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx

For maximum compatibility, combine with Content-Disposition headers:


<FilesMatch "\.(docx|xlsx|pptx)$">
    Header set Content-Disposition "attachment"
    Header set X-Content-Type-Options "nosniff"
</FilesMatch>

Verify using curl before browser testing:


curl -I https://yourserver.com/document.docx

# Should return:
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: attachment; filename="document.docx"
  • Forgetting to restart Apache after config changes (sudo systemctl restart apache2)
  • Conflicts between .htaccess and main config
  • Browser cache retaining old behavior (always test in private mode)

When serving modern Office files (DOCX/XLSX/PPTX) from an Apache web server, browsers sometimes misinterpret these files as ZIP archives. This happens because Office Open XML formats are technically ZIP containers containing XML data, and some browsers prioritize file content over extension.

Apache determines file types using these mechanisms in order:

  1. Explicit Content-Type header in response
  2. File extension mapping via mime.types
  3. Default application/octet-stream

The solution lies in properly configuring the first two options.

Option 1: .htaccess Configuration

Add these lines to your .htaccess file:


<IfModule mod_mime.c>
    AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
    AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx
    AddType application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx
</IfModule>

Option 2: Global mime.types Configuration

Edit /etc/mime.types on Ubuntu and add:


application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet         xlsx
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx

Then restart Apache: sudo systemctl restart apache2

Verify your settings using curl:


curl -I http://yourserver.com/file.docx

You should see:


Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document

For maximum compatibility:

  • Set proper Content-Disposition: Header set Content-Disposition "attachment; filename=\"%f\""
  • Ensure mod_headers is enabled: sudo a2enmod headers
  • Clear browser cache when testing

Correct MIME types ensure:

  • Files open in the correct application
  • Better user experience
  • Prevent security warnings about "invalid file types"
  • Maintain SEO value by serving proper document types