简体   繁体   English

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

[英]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文件夹这是我的项目现在的样子

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

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:你可以做什么:

  1. Install Apache into your machine and configure your local server (will require some effort but you'll have the same setup as on the live environment)将 Apache 安装到您的机器中并配置您的本地服务器(需要一些努力,但您将拥有与实时环境相同的设置)
  2. Run 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.

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