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

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:

    ServerName my.site.com
    ServerAdmin me@site.com
    DocumentRoot /var/www/mysite/
    # Log info redacted #

Virtualhost SSL config:


        ServerName my.site.com
        ServerAdmin me@site.com
        DocumentRoot /var/www/mysite/

        # Log info redacted #
        # SSL Certificate config redacted #

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

        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"


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);


text/html; charset=UTF-8


Wrong on all three counts.

Here is a line from my apache access log (with Content-type added): - - [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": - - [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?

  • 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? – Shane Madden Oct 9 '12 at 15:57
  • I've added the virtualhost config above. No file type handling that I can see. – a coder Oct 9 '12 at 16:10

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">
        <title>Traq Installation<?php echo isset($title) ? " / {$title}" :''; ?></title>

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

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

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.

  • Be sure to select this post as the answer. – Daemon of Chaos Oct 10 '12 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 '12 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.