繁体   English   中英

将项目入口点更改为公用文件夹后样式和 js 不起作用

[英]Style and js doesn't work after changing project entry point to public folder

该项目运行良好,直到我将index.php从项目根目录移动到public文件夹,然后将 css 和 js 从public文件夹移动到assets文件夹这是我的项目现在的样子

  • 上市
    • index.php
  • 资产
    • css
      • 样式.css
    • js
      • main.js -.htaccess

我用php -S localhost:8000加载了服务器

我明白了

Not Found

The requested resource / was not found on this server.

完全忽略我的 .htaccess ! 我什至尝试AllowOverride All之类的解决方案,但仍然无法正常工作,所以我输入php -S localhost:8000 -t public now 站点加载,但 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”

有任何想法吗??

.htaccess 是一个配置文件,用于在运行 Apache ZC6E190B2846334348EZ9E5DZ 服务器软件的 web 服务器上使用。 这意味着当您使用php -S localhost:8000启动项目时,它只会忽略那里写入的路由。

你可以做什么:

  1. 将 Apache 安装到您的机器中并配置您的本地服务器(需要一些努力,但您将拥有与实时环境相同的设置)
  2. public文件夹中运行php -S localhost:8000或使用-t选项设置文档根目录(适用于简单的相对路径,但不适用于 Apache 特定功能,如ModRewrite

祝您的 web 开发之旅好运!

在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM