Skip to main content

How to configure MIME types using the .htaccess file

Learn how to configure MIME types for specific file extensions using your Raidboxes Box's .htaccess file and verify that the correct content type is being served.

Written by Kerstin Kegel

What is a MIME type?

A MIME type (Multipurpose Internet Mail Extensions) describes the format of a file. The web server sends this information to the browser through the HTTP Content-Type header.

This helps the browser determine how to process or display the file.

Common MIME types include:

  • text/html – HTML documents

  • text/css – CSS files

  • application/javascript – JavaScript files

  • application/json – JSON files

  • application/octet-stream – generic binary files

ℹ️ Technical note

This article is intended for users with basic knowledge of editing server configuration files. Incorrect changes to the .htaccess file may affect your website's functionality or availability.


When do I need to change a MIME type?

You may need to change a MIME type if your web server returns an incorrect content type for a particular file extension or does not recognize the extension correctly.

Important: Not every MIME type error requires a change to the .htaccess file.

Especially after a website migration or domain change, outdated cache files or incorrect file paths can cause similar issues. First, check whether the affected file is accessible and whether the error persists after clearing the cache.

For some themes or page builders, regenerating the CSS files may also resolve the issue.


What do I need to edit the .htaccess file?

Before making any changes, make sure you have:

  • SFTP or SSH access to your Box

  • A suitable text editor, such as Visual Studio Code or Notepad++, if you are using SFTP

  • A backup copy of your current .htaccess file

We also recommend creating a manual backup of your Box in the Raidboxes Dashboard before changing its configuration.


How do I add MIME types using the .htaccess file?

You can configure MIME types in your .htaccess file using either SFTP or SSH. The following instructions explain the SFTP method first.

If you prefer using SSH, you'll find an alternative method further below.

Add MIME types using SFTP

1️⃣ Connect to your Box

Connect to your Box using an SFTP client such as FileZilla or Cyberduck. You can find the required login credentials in your Raidboxes Dashboard.

2️⃣ Locate the .htaccess file

Open the wordpress directory. This is where you'll find the .htaccess file.

3️⃣ Open the file for editing

Download the .htaccess file to your computer or open it in a text editor through your SFTP client.

Save a copy of the original file before making any changes.

4️⃣ Add the MIME type

Use the Apache AddType directive to assign a specific MIME type to a file extension.

Syntax:

AddType MIME-type .file-extension

Example:

AddType application/json .remotemanagement

This directive assigns the MIME type application/json to files with the .remotemanagement extension.

You can add multiple AddType directives on separate lines.

ℹ️ Note: Make sure you don't assign conflicting MIME types to the same file extension.

5️⃣ Save your changes

Save the modified .htaccess file and, if necessary, upload it back to the original directory on your Box.

6️⃣ Verify the change

Open the affected file in your browser and check whether the web server returns the intended MIME type.

The next section explains how to verify the MIME type.

Alternative: Add MIME types using SSH

If you're familiar with SSH, you can edit the .htaccess file directly in the terminal.

a) Connect to your Box using SSH.

b) Navigate to the www directory, which contains your WordPress installation:

cd www

c) Open the .htaccess file using the nano text editor:

nano .htaccess

d) Add the required AddType directive as described above.

e) Save the file using Ctrl + O, confirm with Enter, and exit the editor using Ctrl + X.

f) Verify the MIME type as described in the next section.


How can I check the MIME type of a file?

You can check the MIME type using your browser's developer tools:

  1. Open the affected file or website in your browser.

  2. Open the developer tools, for example by pressing F12.

  3. Switch to the Network tab.

  4. Reload the page and select the affected file.

  5. Under Response Headers, look for Content-Type.

For the example above, the response header should look like this:

Content-Type: application/json

This allows you to verify which MIME type the web server is actually returning.


How can I check the MIME type of a file?

You can check the MIME type using your browser's developer tools:

  1. Open the affected file or website in your browser.

  2. Open the developer tools, for example by pressing F12.

  3. Switch to the Network tab.

  4. Reload the page and select the affected file.

  5. Under Response Headers, look for Content-Type.

For the example above, the response header should look like this:

Content-Type: application/json

This allows you to verify which MIME type the web server is actually returning.


What can I do if the change doesn't work?

If the file is still being served with an incorrect MIME type, check the following:

  • File path: Is the affected file accessible, or does the server return an error such as HTTP 404?

  • Cache: Clear your website's cache and check the file again.

  • File extension: Does the extension in the AddType directive match the actual file extension?

  • Configuration: Are there other rules that could affect the Content-Type header?

  • HTTP 500 error: If your website displays a server error after the change, remove the directive you recently added or restore your previous .htaccess file.

ℹ️ Note: At Raidboxes, requests are processed by multiple server components. As a result, .htaccess directives may not affect every file request.

If the change causes problems, remove the AddType directive you added or restore your previously saved .htaccess file.


Can I force a file download using MIME types?

A MIME type describes the file format but does not automatically force a download.

To explicitly instruct a browser to download a file, the HTTP header Content-Disposition: attachment is generally used.

The AddType directive alone, therefore, does not guarantee that a browser will download a file instead of displaying it.


📚 Related articles

Did this answer your question?