项目运行良好,直到我将index.php
从项目根目录移至public
文件夹,然后将css和js从public
移至assets
文件夹
这是我的项目现在的样子
我向服务器加载了php -S localhost:8000
我得到
Not Found
The requested resource / was not found on this server.
完全忽略我的.htaccess!我什至尝试了类似的解决方案
AllowOverride All
但仍然行不通
所以我打了
php -S localhost:8000 -t public
现在站点加载了,但是css / js甚至根本就不起作用!
当我打开控制台时,我得到
The script from “http://localhost:8000/assets/js/main.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type
Loading failed for the <script> with source “http://localhost:8000/assets/js/main.js”
任何想法?
答案 0 :(得分:1)
.htaccess是一个配置文件,可在运行Apache Web Server软件的Web服务器上使用。这意味着,当您使用php -S localhost:8000
开始项目时,它只会忽略在此编写的路由。
您可以做什么:
php -S localhost:8000
文件夹中运行public
或使用-t
选项设置文档根目录(仅适用于简单的相对路径,但不适用于要使用{{1 }})祝您在Web开发过程中一切顺利!
答案 1 :(得分:0)
在index.php文件中进行以下更改
<link rel="stylesheet" type="text/css" href="../assets/css/style.css">
<script src="../assets/js/main.js"></script>