XAMPP 安装程序为 CSS 个文件提供了错误的 MIME 类型

XAMPP setup gives wrong mime type for CSS files

作为一名初级前端开发人员,我最近一直在尝试 MySQL 和 PHP,希望有一天能成为一名全栈工程师。我已经建立了一个小型服务器和数据库。我是 运行 通过 XAMPP,在本地主机上。

这就是事情变得有趣的地方。当我浏览我的小网站时,我的 CSS 和 JavaScript 被加载,但完全是空的。让我为您说明一下:

The horror of empty sources

接下来,我在控制台中收到一条警告:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/public/css/style.css".

即使我在我的 HTML 中将类型定义为 text/css,它也会一直给出这个。现在这个问题在过去两天让我非常疯狂,我不知道如何解决它。可能是我的文件夹结构有问题吗?我是否需要向我的 .htaccess 文件添加或更改某些内容?所有帮助将不胜感激!!

文件夹结构

--App

------Classes

------Controllers

------Models

------Views

----------Partials

--Lib

------Bootstrap

------NPM

--Public

------css

------img

------js

这听起来很像 .htaccess 问题。

更有可能的是,每个请求都被重写为通过 public/index.php,采用典型的前端控制器模式。

但是,我们只想在 public 文件夹中实际不存在这些文件时才这样做。

这是提供此解决方案的 .htaccess

RewriteEngine On

# The following rule tells Apache that if the requested filename
# exists, simply serve it.

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]


# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.

RewriteCond %{REQUEST_URI}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]