Php – Apache ForceType / SetHandler not responding as expected

apache-2.4PHP

I am trying to force apache to handle a file (or directory of files) as php regardless of file extension.

The link to the file should be as follows,
Http://mysitehere.info/sig2/name.png

I have tried,

<FilesMatch “\.(jpg|jpeg|png|gif|swf|flv|ico)$”>
SetHandler application/x-httpd-php
</FilesMatch>

This does not work, returning a broken image icon with, the name.png filename and a 404 not found when tried with sig2/name.png/

I have also tried,

<Files .+*^$[]()>
ForceType application/x-httpd-php
SetHandler application/x-httpd-php
</Files>

I had gotten that .htaccess file content from ForceType Sethandler Code Why Does This Work
This returned the same results as the first try. Nothing but 404 or a broken image.

I also tried,

<Files "name.png">
SetHandler application/x-httpd-php
</Files>

This does "work" but it doesn't do what it needs to. Accessing the image by name.png gives me a broken image. Accessing it by name.png/ works for some reason that I am unsure of.

I have made sure that AllowOverride All is set in my httpd.conf for the directory of the image(s).
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require All Granted
</Directory>

This should be enough to get Sethandler or ForceType to work I would assume however I still can't get the effect I want. Note, I do not have mod_rewrite installed to my server. Also of note that SetHandler and ForceType have the same results when used with <Files "name.png">
I am running PHP 5.5.9? and the latest version of Apache2.

With that, am I doing something horribly wrong or do I have a missing module required for sethandler?

Best Answer

I had found out a major mistake in my code that had set the header to text. This was a fatal error in code and would indeed return a broken image. Fixed the error and all of the above actually work as they should.

Related Topic