作为一名初级前端开发人员,我最近一直在试验 MySQL 和 PHP,希望有一天能成为一名全栈开发人员。我已经建立了一个小型服务器和数据库。我正在本地主机上通过 XAMPP 运行它。
现在这就是事情变得有趣的地方。当我浏览我的小网站时,我的 CSS 和 JavaScript 被加载,但完全是空的。让我为你说明一下:
接下来,我在控制台中收到一条警告:
资源被解释为样式表,但使用 MIME 类型 text/html 传输:“ http://localhost/public/css/style.css ”。
即使我在我的 HTML 中将类型定义为 text/css,它也会不断给出这个。现在这个问题在过去两天让我非常疯狂,我不知道如何解决它。会不会是我的文件夹结构有问题?我是否需要向我的 .htaccess 文件添加或更改某些内容?所有帮助将不胜感激!!
文件夹结构
- 应用程序
------类
------控制器
- - - 楷模
------浏览量
----------部分
--Lib
------自举
------ 新产品管理
- 上市
------CSS
------图像
------js
这听起来非常像一个.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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句