簡體   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