|AddHandler or AddType|
I've never posted in this forum, at least as I'm able to recall.
For more than a decade, I never used PHP. My primary participation has been in the Search Engine forum.
Recently I reactivated a site and resumed with a former host.
Previously the host had a PHP Form Mailer available via CP, which I used for two years.
Upon reactivation, the mailer was no longer available and I had to locate my own script.
The script instructions specified using AddType, which I did and it functioned.
Unfortunately, many visitors were only viewing a single page and no images, which was puzzling.
It turns out the Windows provides a message of malware warning Windows does not recognize this MIME type.
After searching Webmaster World I located some old threads that led me in the right direction, however took some tweaking.
I'm currently using AddHandler. The script functions and single page views have now turned in to normal access (appears the change is acceptable to Windows).
Could somebody possibly explain WHY Windows see's this as malware or perhaps point me toward some references?
AddType and AddHandler are to do with the Apache webserver, not really PHP. You might be using these commands to instruct the server to parse certain files for PHP? What was the full AddType / AddHandler statements?
|What was the full AddType / AddHandler statements? |
(per the script instructions)
AddType x-httpd-php .html
AddHandler x-httpd-php .html
As I understand it AddType tells the browser what mime-type the specified file extensions should be - in other words telling the browser how to handle the file. AddHandler, on the other hand, tells the server how to process files with the specified file extensions. They do different things.
In your case (with AddHandler) you are telling the server to send all .html files through the PHP engine.
|AddType x-httpd-php .html |
This looks wrong to me, I don't believe "x-httpd-php" is a valid mime-type and this probably explains your Windows error message. If anything (IMHO) it should be "application/x-httpd-php"...
AddType application/x-httpd-php .html
However (and this is where my server knowledge is flagging - so if someone else can please explain), despite seeing examples of this all over the web, I don't know why AddType would be required in this way. AFAIK the default mime-type for .html files is text/html which I would have thought would be OK?
|AddType application/x-httpd-php .html |
This is actually what the script instructions specified, however the script would not function with this line.
Did a google and went through plenty of references before locating one in which suggested removing application.
The script functioned fine after that.
Many thanks for your help.
The AddType / AddHandler stuff is beyond confusing and I usually end up trying several combinations before I find the one that works OK.
On some server configurations, both directives need to be implemented.
AddType application/x-httpd-php .php .html
AddHandler application/x-httpd-php .php .html
My understanding is that penders's description of what the two directives are supposed to do (and what they're for) is exactly right, but in some Apache versions it is necessary to use a workaround to achieve the desired effect on the server, which leads to the many variations of the two lines that you find. Some configurations require AddType, others AddHandler, and others require both. And the precise syntax required for each line also varies with version/configuration.
First look for a FAQ or KB page at your host with explicit instructions for their servers (usually titled something like "parse html files as php").
If none found, search online for forum posts by other users of your webhost describing what worked for them.
If none found, use random examples you find online and experiment until one works.
|Some configurations require AddType, others AddHandler, and others require both. |
I just had a quick go on my local test server which runs PHP as an Apache module and I am required to use AddType (not AddHandler) in a per directory .htaccess file in order to get .html files processed by PHP, of the form...
AddType application/x-httpd-php html
(The mime-type is somehow transmogrified into text/html when sent to the client.)
I have read that if you run PHP as CGI then you will need to use AddHandler instead. (It's funny, in my head it feels like it should be the other way round!? But as mentioned... confusing!)