Posts tagged: apache

Downloading PHP: Not Exactly What You Were Expecting…

This was an interesting problem I just encountered. While moving a virtual host from an older Apache server to a more modern Apache server the customer’s site on the new server wanted us to download all the htm files. On initial inspection the first oddity I discovered was that they were registering .htm and .html files with the x-httpd-php mod_php module in their .htaccess file.

AddType application/x-httpd-php .html .htm

After over coming the initial wave of announce I started checking the obvious things. First I made sure php was working at all. Because .php files were loading I knew that mod_php was loaded for this virtual host. I checked the handler for it to make certain that x-httpd-php was being used. I also tried x-httpd-php5. Upon downloading the files I noticed that they were unprocessed by php. Lastly I checked the AllowOverride directive, only finding that our server allows all overrides.

Finally I stumbled on to the problem. There already was an AddType for .html and .htm files along with .shtml .shtm files. The mod_include, the server side include or ssi for short, module was registering them and Apache was not replacing that with what was in the vhost’s .htaccess file. The first solution to the problem was to remove the .htm and .html files from mod_include. The problem with my first solution was that if anyone was using mod_include and using .htm and .html files they would just stop working.

My final solution to the problem was to RemoveType .htm and .html before AddType .htm and .html . Keep in mind that most browsers cache the file and the mime type. I had to clear my browser cache before I was successfully able to view the site. Below is the final configuration.

RemoveType .htm .html
AddType application/x-httpd-php .html .htm