JS/CSS 404 找不到使用 Slim Framework

JS/CSS 404 not found using Slim Framework

我已经阅读了 this 问题,但没有解决我的问题,即使非常相似。

我正在使用 Slim 框架。

这是我的项目结构。 Slim 路由发生在 public 文件夹中。

页面 templates/index.phtml 需要一些 JS 和 CSS,但我得到 404 未找到。

我的 templates/index.phtml 需要:

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My WebSite</title>
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="style/global.css">
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="script/index.js"></script>
</head>

然后我得到(例如 index.js):

Not Found

The requested URL /index.js was not found on this server.

Apache/2.4.18 (Ubuntu) Server at blah.blah.blah Port 443

我对 Slim 框架不太熟悉,但我知道您使用的是 routerpublic 文件夹,这让我相信它无法访问 index.js 因为它超出了范围。也许尝试将 script 文件夹移动到 public 文件夹中,看看是否可行! :)