【问题标题】:XAMPP setup gives wrong mime type for CSS filesXAMPP 设置为 CSS 文件提供了错误的 mime 类型
【发布时间】:2018-11-28 06:41:03
【问题描述】:

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

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

The horror of empty sources

在此旁边,我在控制台中收到一条警告:

资源被解释为样式表,但使用 MIME 类型 text/html 传输:“http://localhost/public/css/style.css”。

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

文件夹结构

--应用程序

-----类

-----控制器

-----型号

-----观看次数

---------部分

--库

------引导

-----NPM

--公开

------css

------图片

------js

【问题讨论】:

  • 您的文件结尾是否正确?您是否更改了 xampp 配置中的某些内容? CSS 是否通过 PHP 发送?
  • 你有一个.htaccess 通过 index.php 重新路由所有内容吗?如果有,请粘贴
  • 不应该是localhost/[your-project-name]/public/style.css吗?
  • 这与 MVC 无关(已编辑问题以删除无意义的流行语)
  • @Saad 这就是他设置的虚拟主机配置。两者都有可能

标签: css .htaccess xampp


【解决方案1】:

这听起来很像 .htaccess 问题。

很有可能,每个请求都被重写以通过public/index.php,在典型的前端控制器模式中。

但是,我们只想在文件实际上不存在于公用文件夹中时这样做。

这是提供此解决方案的.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}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

【讨论】:

    猜你喜欢
    • 2015-09-21
    • 2015-09-26
    • 1970-01-01
    • 2012-06-29
    • 2018-10-15
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多