Apache misconception with AddType and AddHandler
Having seen an interesting post over at the ISC about apache’s interpretation of file extensions, I thought I’d have a quick look into what is happening.
I have found that by using:
AddHandler php5-script .php
any file containing .php (this.php that.php.gif) will be parsed by php.
using:
AddType application/x-httpd-php .php
any file that doesn’t have a further extension as a registered mime type (this.php.foo) will be php parsed
this.php.gif will not, unless the server doesn’t define .gif in its apache configuration/ mime.types file.
Still not quite good enough, the answer comes from a section of apache’s mod_mime documentation covering multiple file extensions.
To force only files that end with .php to be php parsed, use a FilesMatch section
<FilesMatch \.php$>
SetHandler php5-script
</FilesMatch>
or, as is my preference, files that end in .php, .html or .htm
<FilesMatch \.(php|html|htm)$>
SetHandler php5-script
</FilesMatch>
YES! This did it. Great info, Thanks. Had a problem with all .htm .html & .php to work the same. Fooled around with SetHandler and AddHandler starting to wonder if I found a bug….(in Apache!?!?!) but sure it’s behind the keyboard as usual
Thanks!
December 2nd, 2009 at 1:35 pm