Disable PHP Execution for a Specific Folder in Apache

There was a scenario where I set the handler for PNG files to the PHP engine for a certain directory. In this case, it was a barcode generator script and I didn’t want the extension to be .php. In the same directory, however, I had actual PNG files that the PHP engine attempted to parse. When users tried to access those files, an compile error would show up (what actually showed was a broken image). Anyway here’s a method to disable PHP execution for a specific folder in Apache, just place it in an .htaccess file for the folder you want to disable PHP compilation:

SetHandler default-handler
Options None
AllowOverride None

You can also do certain files, in this case any files that end with .actual.png:

<FilesMatch "\.actual\.png$">
  SetHandler default-handler
  Options None
  AllowOverride None
</FilesMatch>