Forum Moderators: phranque
AddType application/x-httpd-php .php AddType text/html .php AddType application/x-httpd-php .php AddHandler application/x-httpd-php .php AddHandler php5-script .php AddHandler php5-script .php
AddType text/html .php "The AddType / AddHandler stuff is beyond confusing and I usually end up trying several combinations before I find the one that works OK."
"The theoretically-correct way to tell Apache to execute a script is to use the AddHandler directive. However, due to a kludge in the way PHP was first implemented, the seemingly-nonsensical application of the AddType directive is sometimes required. As I understand it, whether you need to use AddHandler or AddType depends on whether your PHP is installed as a module or as CGI."
"You're also fighting "institutionalized" confusion between the very-different functions of AddType (which defines the MIME-type header to be returned with content to the client), and AddHandler, which tells the server how to handle each filetype in the server's filespace.
The examples posted above demonstrate this "institutionalized" confusion; Although the use "AddHandler application/x-httpd-php .php" to declare a MIME-type as a content-handler is glaringly nonsensical, the fact is that it will work on some servers."
AddType principally adds a content type header to the HTML page that is output.
AddHandler principally tells Apache to invoke a PHP handler for .php files. There are several ways of doing that, hence several variations in the syntax.
The functionality and the syntax has also varied between Apache 1.3, 2.2 and 2.4.
As I can never remember the "right way" for each version, and what you need to do can also depend on other server settings set by the host, it often is a case of trying different things until it works.
[edited by: jmnielsen7 at 3:43 pm (utc) on Mar 22, 2013]
The Action directive allows CGI scripts to be used as handlers. It has two variants: associating a script with either a media type or an arbitrary name, which can then be used by the AddHandler and SetHandler directives.
Apache understands several different MIME types for differentiating various kinds of media. You can add your own handler to process one of them by using the Action directive with a MIME-type parameter:
Action image/gif /cgi-bin/gifconvert.cgi
You can invent new media types or supplement existing ones using AddType in combination with Action, but this approach is deprecated in favor of using AddHandler or SetHandler. For example, to allow a different extension for SSIs, you could use this:
AddType application/x-server-parsed .ssi
or to invent a completely new media type and have it parsed with your own handler, you could use this:
Action text/my_text_type /cgi-bin/my_text_type_handler
AddType text/my_text_type .mytext
In addition to the internal handlers provided by Apache modules, you can also define your own handlers with the Action directive. This is similar to using Action with MIME types but with an arbitrary handler name:
Action my_handler /cgi-bin/my_handler
AddHandler my_handler .mytext
This provides an excellent way to hide CGI scripts behind seemingly ordinary URLs; the handler can be associated with a directory, and then any file request in that directory will instead go to the handler."