资源被解释为样式表但使用 MIME 类型 text/html 传输

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10553638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:21:24  来源:igfitidea点击:

Resource interpreted as stylesheet but transferred with MIME type text/html

csshtmlapache

提问by Shoe

This is my html:

这是我的 html:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv = "Content-Language" content = "en"/>
        <meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="/xxx/app/www/style.css">

Now when I load the page, Safari's inspector gives me:

现在,当我加载页面时,Safari 的检查器会给我:

Resource interpreted as stylesheet but transferred with MIME type text/html

资源被解释为样式表但使用 MIME 类型 text/html 传输

I'm working on localhost with MAMP. I'm not sure what to modify to get this to work. I read that this might be a server problem of some kind.

我正在使用 MAMP 在本地主机上工作。我不确定要修改什么才能使其正常工作。我读到这可能是某种服务器问题。

How do I solve it?

我该如何解决?

回答by Fabrizio Calderan

Create an .htaccessfile into your root folder (or update the existing one) with this line inside

.htaccess在您的根文件夹中创建一个文件(或更新现有文件),其中包含这一行

AddType text/css .css 

this will tell apache to send the right content-typeheader for .cssfile

这将告诉 apache 发送正确content-type.css文件头

回答by Sid

There is possibility that not just css resources were interpreted wrongly. It maybe a problem of your webserver configuration.

有可能不仅仅是 css 资源被错误地解释。这可能是您的网络服务器配置的问题。

The best way to check is to go to Chrome -> Network tab and check responses section for each request. Also you can run $ curl -I http://path_to_file_or_pagewith terminal and have a look at response, you should see it in following format, e.g. Content-Type: image/jpeg

检查的最佳方法是转到 Chrome -> 网络选项卡并检查每个请求的响应部分。您也可以$ curl -I http://path_to_file_or_page使用终端运行并查看响应,您应该以以下格式看到它,例如Content-Type: image/jpeg



So, if it will occur that webserver (apache) does it for all filesthen you can try to solve the problem in following way:

因此,如果出现 webserver (apache) 对所有文件都执行此操作的情况,那么您可以尝试通过以下方式解决问题:

Check your /etc/apache2/apache2.confIf there are any SetHandler application/x-httpd-phpline, try to comment it and then reload your apache by $ sudo system apache2 reload

检查您的/etc/apache2/apache2.conf如果有任何SetHandler application/x-httpd-php行,请尝试对其进行评论,然后通过以下方式重新加载您的 apache$ sudo system apache2 reload

Let us know if the problem is still there.

如果问题仍然存在,请告诉我们。