作为一名初级前端开发人员,我最近一直在尝试使用MySQL和PHP,希望有朝一日能成为一个全栈的人。我已经建立了一个小型服务器和数据库。我通过XAMPP在localhost上运行它。
现在这就是事情变得有趣的地方。当我浏览我的小网站时,我的CSS和JavaScript被加载,但是完全是空的。让我为你说明一下:
接下来,我在控制台中收到一条警告:
资源解释为样式表,但使用MIME类型text / html传输:" http://localhost/public/css/style.css"。
尽管我在HTML中将类型定义为text / css,但仍然保留了这一点。现在这个问题让我在过去两天绝对疯狂,我不知道如何解决这个问题。这可能是我文件夹结构中的问题吗?我是否需要在.htaccess文件中添加或更改内容?非常感谢所有帮助!!
文件夹结构
- 应用
------类
------控制器
------模型
------浏览
----------局部模板
- 库
------引导
------ NPM
- 公共
------ CSS
------ IMG
------ JS
答案 0 :(得分:0)
这听起来像是一个.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]