Refused to apply style from 'style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

今天把 Laravel 專案放到新建的 server 跑,出現了這個錯誤:

Refused to apply style from ‘http://localhost:8080/assets/styles/style.css’ because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.

找了很久都沒有找到原因,同時伴隨著部分頁面會出現 404。

Stackoverflow 這篇講了很多,但實際上我遇到的倒沒有這麼複雜,而且也不是因為因為 lib 引起的問題,最後在這篇找到解答,原來我只是忘記設定 Apache 的 Allow Override

1
2
3
4
5
6
7
DocumentRoot /var/www/sitefolder/public
ServerName site.domain.com
<Directory /var/www/sitefolder/public>
    AllowOverride All # 加上這行就可以了
    Allow from all
    Options +Indexes
</Directory>

最後執行 sudo systemctl reload apache2 就正常了。

References

comments powered by Disqus