不正确的MIMEtypes – 拉出我的头发

我有一个CSS文件被Apache错误地标记为文本/ html的问题。 文件types在浏览器中不匹配,并且被忽略导致显示失败。

我在RHEL 5服务器上使用Apache 2.2.3。

我已经尝试将此添加到httpd.conf并重新加载与service httpd reload加载configuration:

 AddType text/css .css 

浏览器看不到变化。 我的CSS文件仍然显示text/html (即使当我使用PHP curl探测MIMEtypes..它没有区别,服务器发送一个text/html文件)

然后,我从httpd.conf注释掉了下面几行,确保一些不可思议的事情发生:

 LoadModule mime_magic_module modules/mod_mime_magic.so <IfModule mod_mime_magic.c> MIMEMagicFile /usr/share/magic.mime MIMEMagicFile conf/magic </IfModule> 

一旦这些被搁置,我保存并重新加载configuration。 不用找了。 .css文件仍然以text/html

虚拟主机标准configuration:

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

虚拟主机SSLconfiguration:

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

以下是我从shell获得的内容:

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

这是我从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 text/plain 

错误的三个方面。

下面是我的apache访问日志中的一行(添加了Content-type):

 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" 

包含在同一页面中的不存在的css文件也以“text / html”的forms返回:

 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" 

那么…我在这里忽略了什么?

我终于发现了这个问题。 Traq安装视图文件install / views / layout.php在该文件的顶部包含一个文档types:

 <!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> 

删除顶部行<!doctype html>解决了这个问题。 包含的css文件现在被视为acutal css文件,并最终出现样式。