Forum Moderators: phranque
I run various websites from an Apache 2 server (VirtualHosts). Actual process is httpd-2.2.0-5.1.2.
Most of the sites use PHP5, so all use .php file extensions.
The problem is that I've just migrated another website here, that has only .htm file extensions.
And when this new site is viewed with a web browser, it displays the source code, i.e. it doesn't build the page from the html.
But if I change the file extension of any file from .htm to .php it is displayed fine by a web browser.
My httpd.conf file contains the following:
DirectoryIndex index.htm index.html index.php
The following directive is present:
TypesConfig /etc/mime.types
and when I've checked this file, it contains the .htm .html file extensions.
I tried adding the following AddType without any luck:
DefaultType text/plain
AddType text/plain .htm
I also tried completing the absolute path of the magic file, which for some reason uses a relative path by default, but again this made no difference:
<IfModule mod_mime_magic.c>
# MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile /etc/httpd/conf/magic
</IfModule>
Obviously I've restarted the httpd process after each change.
What's worrying is that if I removed index.php from the DirectoryIndex directive, my PHP web sites still work fine. It's as if there is a PHP module somewhere that overrides anything httpd.conf
I'm stuck, please can someone suggest something to try.
DefaultType text/plain
AddType text/[b]html[/b] .htm .html
DefaultType text/html
AddType text/html .htm .html
AddType text/plain .txt
At any rate, if you want the browser to render an HTML page, you must serve it with a text/html MIME-type, not text/plain. On many sites, the only plain-text file is robots.txt.
You can use the "Live HTTP Headers" extension for Firefox/Mozilla browsers to see your actual server response headers and verify that the correct Content-type header is being sent by your server.
Jim
I then backed up and replaced httpd.conf with a 'default' file from another webserver that I run, added the site in the VirtualHost directive, and hey presto, it worked!
I then added all my other sites as VirtualHosts, and these too work without any modifications to httpd.conf
So this proves that DirectoryIndex is ignored by Apache, as it's default configuration is:
DirectoryIndex index.html index.html.var
And I'm clearly able to server .htm and .php files.
The other directive we considered is as follows:
DefaultType text/plain
So again it doesn't seem too logical that this works, although as I've previously said, surely the default Apache install servers basic files?!
I've compared by original htttp.conf file with the default one and cannot see any differences at all, so I'm at a loss as to why this works.
So I'm happy that it's working, and thanks for the help.
Sorry I'm not able to provide a solution to this issue that may help others.
If anyone knows why DirectoryIndex is ignored, please let me know.
Thanks.