Resource interpreted as image but transferred with MIME type text/html - Magento

Resource interpreted as image but transferred with MIME type text/html - Magento

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Resource interpreted as image but transferred with MIME type text/html - Magento

When you encounter the error "Resource interpreted as image but transferred with MIME type text/html" while uploading a product image in Magento, it signifies a fundamental mismatch between what the browser expects and what the server delivers. The HTTP protocol relies heavily on MIME types to tell the client how to render content. When an <img> tag requests a file expecting image/jpeg, image/png, or image/gif, but the response headers return text/html, the browser treats the incoming data as a document rather than a picture, triggering this specific console warning.

In a typical Magento deployment, this issue usually stems from one of two scenarios: the .htaccess configuration is incorrectly rewriting image requests to HTML pages, or the server is serving cached HTML content instead of the actual binary image file.

Configuration Rewrite Rules

The most common culprit in shared hosting environments is an overly aggressive .htaccess rule. Magento often relies on Apache modules like mod_rewrite to handle routing and static resource optimization. If a developer adds rules intended to block direct access to certain files (such as preventing hotlinking of images), they might inadvertently rewrite the URL of an actual image file to point to a PHP controller or a default error page.

For instance, if you have a rule that looks something like this:

RewriteRule ^images/\.(.*)$ /index.php [L]

This directive tells Apache to treat any request for a file in the images directory as a request for the Magento front controller (index.php). Since index.php outputs HTML, the server sends back text/html. However, the browser still requests the image, so the MIME type mismatch occurs.

To resolve this, you must inspect your .htaccess files within the root directory and specifically inside any custom static folders (like pub/media). Ensure that no rewrite rules are targeting file extensions like .jpg, .jpeg, .png, or .gif. The rule set should explicitly allow these extensions to bypass the rewrite engine. A standard configuration usually includes:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

This condition checks if a file exists at the filesystem level. If it does, the server serves the file directly without triggering any further rewrites. This is crucial for static assets like images to ensure they are served with their correct binary MIME types.

Cache and Storage Considerations

Another frequent cause involves how static files are stored and cached in Magento. In versions prior to 2.3, Magento used the var/static folder for media caching, while newer versions utilize the pub/media folder directly or a separate cache directory depending on the server setup. If your web server (Nginx or Apache) has its own internal caching enabled, it might serve an old HTML response that was previously generated when an image upload failed.

Additionally, Magento's internal file system cache can sometimes hold onto metadata about files that no longer exist or have changed. If you recently deleted a product image and re-uploaded one with the same filename, or if the file permissions were temporarily incorrect during a manual intervention, the server might attempt to serve the cached HTML response associated with the failed upload attempt.

To mitigate this, clearing the cache is often the first step:

php bin/magento cache:clean
php bin/magento cache:flush

However, simply clearing the application cache might not be enough if the web server itself has cached the wrong MIME type. You may need to purge the server-level cache or touch the file permissions to force a reload. Ensure that the uploaded file actually exists in the target directory and that its MIME type is recognized by the operating system before it is served.

Security Modules and Virtual Hosts

Finally, consider third-party security modules or custom virtual host configurations. Some security plugins intercept requests for media files and return an HTML block containing a "forbidden" message if they detect a potential vulnerability, such as path traversal attempts. While this protects the site, it causes the exact MIME type error described when legitimate users try to view images.

If you are using a specific security module, review its configuration to ensure it does not flag valid image requests for products. Similarly, check your Apache or Nginx virtual host configuration to ensure that the Index directive isn't interfering with direct file access, though this is less common for single-file requests like images.

Ultimately, fixing this error requires ensuring that binary files are served directly from the filesystem without passing through the PHP front controller. Once the .htaccess rules and server configurations allow direct access to media files, the browser will receive the correct text/html content only for actual HTML pages, resolving the console warning.

Our network