Apache returning text/html on some png files

Posted on

Apache returning text/html on some png files – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, apache-2.2, mime, , .

I have an Apache web server that has a sub folder for images.
For some reason, a few of the .png files are returned as text/html and not as image/png.

There is nothing indicating a permission problem and the files return with code 200 and with full size.
I made sure that image/png is set and even tried forcing it with .htaccess

Any idea where to look next?

Edit: looks like an .htaccess configuration problem on a parent directory.

Solution :

Did you make sure png files are valid image files? If you are on a Linux platform you can try the file command

file somefile.png

That command should return something along the lines of

PNG image data, 318 x 15, 8-bit/color RGB, non-interlaced

You can also try to view the file with a image viewer.

The problem for me was that the image file to be delivered was named pear.php.net-sos8j3lis2j.png.

Apache’s AddHandler directive – that’s used to assign the PHP interpreter to .php files
– supports multiple extensions, and pear.php.net.png was seen as having three extensions: .php, .net and .png. .php was the first, to the php interpreter was invoked.

text/html was then sent out by either apache or PHP, I don’t know.

What I had to do to fix the problem:

Replace all instances of

AddHandler php-cgi .php


<FilesMatch .php$>
    SetHandler php-cgi

Maybe look for .png, .PNG, .pNG and .PNg.

Leave a Reply

Your email address will not be published. Required fields are marked *