[英]Style and js doesn't work after changing project entry point to public folder
The project was working fine till i moved index.php
from project root to public
folder then moved css and js from public
to assets
folder here is how my project looks like now该项目运行良好,直到我将
index.php
从项目根目录移动到public
文件夹,然后将 css 和 js 从public
文件夹移动到assets
文件夹这是我的项目现在的样子
i loaded the server with php -S localhost:8000
我用
php -S localhost:8000
加载了服务器
i get我明白了
Not Found
The requested resource / was not found on this server.
ignoring my .htaccess completely !完全忽略我的 .htaccess ! i even tried solutions like
AllowOverride All
but still doesn't work so i typed php -S localhost:8000 -t public
now site loads but css/js doesn't work at all even inline style !我什至尝试
AllowOverride All
之类的解决方案,但仍然无法正常工作,所以我输入php -S localhost:8000 -t public
now 站点加载,但 css/js 即使是内联样式也根本不起作用! when i open console i get当我打开控制台时,我得到
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”
any ideas??有任何想法吗??
.htaccess is a configuration file for use on web servers running the Apache Web Server software. .htaccess 是一个配置文件,用于在运行 Apache ZC6E190B2846334348EZ9E5DZ 服务器软件的 web 服务器上使用。 It means that when you start project with
php -S localhost:8000
it simply ignores the routes written there.这意味着当您使用
php -S localhost:8000
启动项目时,它只会忽略那里写入的路由。
What you can do:你可以做什么:
php -S localhost:8000
inside public
folder or using -t
option to set the document root (will work for simple relative paths but not when you want to use Apache specific features like ModRewrite
)public
文件夹中运行php -S localhost:8000
或使用-t
选项设置文档根目录(适用于简单的相对路径,但不适用于 Apache 特定功能,如ModRewrite
) Good luck with your web development journey!祝您的 web 开发之旅好运!
In index.php file do the below changes在 index.php 文件中进行以下更改
<link rel="stylesheet" type="text/css" href="../assets/css/style.css">
<script src="../assets/js/main.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.