css未加载,因为其MIME类型“text / html”不是“text / css”

我正在使用netbeans 8.2 ide,Apache 2.4和php7。</ p>

I 已经下载了Bootstrap,我试图将它链接到index.php我已经不远了。 当我在localhost上测试示例页面时,错误“css未加载,因为它的MIME类型,”text / html“,不是”text / css“”</ p>

我试过的东西 (重新启动每个之间的erver):</ p>

  • 我的httpd.conf文件中的“AddType text / css .css”以及vhost </ li>
  • 确保php strict_mode关闭(在帖子中看到)</ li>
  • 检查mime.types的类型(在那里)text / css - css </ li>
  • 将default_mimetype =“text / html”更改为php.ini文件中的default_mimetype =“”</ p>

    </ p> </ li>
    </ ul> \ n

    更新</ p>

    我做了更多的研究结果证明PHP会将.css解析为html,无论出于何种原因并更改其mime类型(不完全确定这一切是如何工作但是 似乎是这样的)。 所以我将.css文件重命名为.php文件,并将代码添加到每个.css文件中</ p>

      header('Content-type:text / css',true); \  n </ code> </ pre> 

    这不起作用,然后我将以下内容添加到index.php中:</ p>

      header(“X-  Content-Type-Options:nosniff“); 
    </ code> </ pre>

    由于缺少mime类型,这只是阻止了样式表的加载! 甚至与Content-type一起使用。</ p>

    我还包括对服务器的请求和响应标头的捕获在此处输入图片说明 </ p>

    非常感谢您的任何帮助,这是非常令人沮丧的我想要进入一些 基本的网页设计,但我甚至无法通过包含的Netbeans模板。 我觉得这与PHP7或Apache 2.4的配置有关,但我不知道下一步</ p>
    </ div>



I am using netbeans 8.2 ide, Apache 2.4 with php7.

I have downloaded Bootstrap and am trying to link it into index.php i haven't far. When I test the example page on localhost I the error "css was not loaded because its MIME type, “text/html”, is not “text/css”"

Things I have tried (restarting the erver between each):

  • "AddType text/css .css" in my httpd.conf file and also in vhost
  • ensured php strict_mode is off (saw it in a post)
  • checked mime.types for the type (which is there) text/css - css
  • changed default_mimetype = "text/html" to default_mimetype = "" in the php.ini file


I did a bit more research turns out PHP will parse .css as html for whatever reason and change its mime type ( not exactly sure how that all works but seems to be the case). So I renamed the .css files as .php files and added the code into each .css file

header('Content-type: text/css', true);

this did not work, I then added into index.php the following:

header("X-Content-Type-Options: nosniff");

this just prevented the loading of the stylesheets because of lack of mime type at all! even in conjunction with Content-type.

also i have included a capture of the request and response headers to the serverenter image description here

thank you very much for any help this is very frustrating I'm trying to get into some basic web design but I can't even make it past the included Netbeans template. I have a feeling it's something to do with the configuration of PHP7 or Apache 2.4 but i have no idea were to go next

duangu1878 是的,是的。我确实声明了text/css。样式表是.css和bootstrapjs加载正常。我正在使用netbeans标准模板,当索引是.html时可以正常工作,但是当我更改它.php时没有。
3 年多之前 回复
dongyixun0634 特别是,您是不是尝试使用<link>加载引导程序js组件。
3 年多之前 回复
doujionggan9570 你可能做了些蠢事。检查文件扩展名是否为.css
3 年多之前 回复
douwen7331 你声明了type=“text/css”<linkrel=“stylesheet”type=“text/css”href=“your/css/file.css”>
3 年多之前 回复


我最终卸载了我自己配置​​的Apache服务器,并安装了预配置的WAMP Apache服务器,解决了我的问题,因此在某处出现了配置问题 不知道什么,但现在一切都很好。</ p>
</ div>



I ended up uninstalling my self configured Apache server and installed the pre-configured WAMP Apache server which solved my problem so there a configuration problem somewhere not sure what but everything is working great now.

Csdn user default icon