teh fear

07 Apr

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>

One Response to “Apache misconception with AddType and AddHandler”

  1. 1
    Martin Erlandson Says:

    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!

Leave a Reply

© 2010 teh fear | Entries (RSS) and Comments (RSS)

Powered by Wordpress