2

I have a problem with CSS files being incorrectly marked text/html by Apache. The file type is mismatched in the browser, and is ignored causing display failures.

I'm using Apache 2.2.3 on a RHEL 5 server.

I've tried adding this to httpd.conf and reloading config with service httpd reload:

AddType text/css .css

No change as seen by the browser. My css file is still showing text/html (even when I use php curl to probe the mime type.. it makes no difference, the server is sending out a text/html file)

I then commented out the following lines from httpd.conf, to make sure something screwy wasn't going on with magic:

LoadModule mime_magic_module modules/mod_mime_magic.so

<IfModule mod_mime_magic.c>
  MIMEMagicFile /usr/share/magic.mime
  MIMEMagicFile conf/magic
</IfModule>

Once those were set aside, I saved & reloaded the config. No change. The .css files are still coming across as text/html.

Virtualhost standard config:

<VirtualHost 1.2.3.4:80>
    ServerName my.site.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/mysite/
    # Log info redacted #
</VirtualHost>

Virtualhost SSL config:

<VirtualHost 1.2.3.4:443>

        ServerName my.site.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/mysite/

        # Log info redacted #
        # SSL Certificate config redacted #

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
            SSLOptions +StdEnvVars
        </Files>

        SetEnvIf User-Agent ".*MSIE.*" \
                 nokeepalive ssl-unclean-shutdown \
                 downgrade-1.0 force-response-1.0

        CustomLog logs/ssl_request_log \
                  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

Here's what I'm getting from shell:

[boxor]# file --mime install.css
install.css: text/x-c; charset=us-ascii

Here's what I'm getting from php:

$file = 'https://my.site.com/traq/install/install.css';
echo mime_content_type($file);

$file = $_SERVER['DOCUMENT_ROOT] . '/traq/install/install.css';
echo mime_content_type($file);

returns:

text/html; charset=UTF-8

text/plain

Wrong on all three counts.

Here is a line from my apache access log (with Content-type added):

1.2.3.4 - - [10/Oct/2012:08:32:38 -0400] "GET /traq/install//install.css HTTP/1.1" 200 2600 "http://my.site.com/traq/install/" "text/html" "Mozilla/5.0 blahblah Firefox/15.0.1"

A non-existent css file included on the same page is also returned as "text/html":

1.2.3.4 - - [10/Oct/2012:09:11:11 -0400] "GET /traq/install/idontexist.css HTTP/1.1" 200 2600 "http://my.site.com/traq/install/" "text/html" "Mozilla/5.0 blahblah Firefox/15.0.1"

So... What am I overlooking here?

2
  • What's your virtual host config look like? Specifically, are there any request handlers involved other than Apache itself serving static content from the filesystem? Oct 9, 2012 at 15:57
  • I've added the virtualhost config above. No file type handling that I can see.
    – a coder
    Oct 9, 2012 at 16:10

1 Answer 1

2

I finally discovered the problem. The Traq installation view file, install/views/layout.php included a doctype at the top of this file:

<!doctype html>
<html lang="en" dir="ltr">
    <head>
        <title>Traq Installation<?php echo isset($title) ? " / {$title}" :''; ?></title>

        <style type='text/css'>
            @import '/traq/install/install.css';
            @import '/traq/install/test.css';
        </style>


    </head>
    <body>
        <div id="wrapper">
            <header id="head">
                <h1>Traq Installation</h1>
                <h2><?php echo isset($title) ? $title :''; ?></h2>
            </header>
            <div id="page">
                <?php echo $output; ?>
            </div>
            <footer>
                Traq &copy; 2009-<?php echo date("Y"); ?> Traq.io
            </footer>
        </div>
    </body>
</html>

Removing the top line <!doctype html> solved the problem. The included css files are now seen as acutal css files, and the styles finally appear.

2
  • Be sure to select this post as the answer. Oct 10, 2012 at 14:47
  • I will do that tomorrow. Also, if you find the question or answer helpful, please don't forget to vote.
    – a coder
    Oct 10, 2012 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .