Forum Moderators: phranque

Message Too Old, No Replies

Web pages served as plain text/code only

         

64x2

4:22 pm on Jul 2, 2007 (gmt 0)

10+ Year Member



Hi,

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.

jdMorgan

4:32 pm on Jul 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's likely that you want something like:

DefaultType text/plain
AddType text/[b]html[/b] .htm .html

if most of the files you serve are plain-text, or perhaps

DefaultType text/html
AddType text/html .htm .html
AddType text/plain .txt

if most of the files you serve are html-content pages (note that I'm talking about the content sent to the browser, regardless of whether it came straight out of a static HTML-format file on disk or was produced by PHP).

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

64x2

12:44 am on Jul 3, 2007 (gmt 0)

10+ Year Member



Thanks, I'll give this a try.

I meant to say, my httpd.conf file is virtually unchanged, apart from the Virtual Hosts directive.

How come I have to change things just to serve .htm files? Surely this is the most common type of web page?

jdMorgan

1:31 am on Jul 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since I don't know anything about your host, I can't answer that question. It is rather odd, though, to have the default MIME-type declared as text/plain.

Jim

64x2

11:37 am on Jul 3, 2007 (gmt 0)

10+ Year Member



I tried that AddType, but it still didn't work.

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.