给出 404 Not Found in PHP 的链接

Links giving 404 Not Found in PHP

下面是我的代码结构

/public
  index.php
  about.php
  /srv
     ->srv1.php
  /solutions
     ->solution1.php
  /common
     ->header.php
     ->footer.php
  /resources
     /img
       ->img1.png
  /js

我做了什么-->

  1. 包含 header.php & footer.php 到所有带有简单 include('common/header.php');
  2. 的页面
  3. 作为包含在页眉和页脚中的徽标 img1.png
<img src='resources/img/img1.png'>
  1. 页眉和页脚中存在链接
<a href='srv/srv1.php'>Services</a>
<a href='solutions/solution1.php'>Solutions</a>

面临的问题 -->

  1. 当我转到页面 srv1.php - 页眉和页脚工作正常但徽标 (img1.png) 不显示

我遇到以下错误 --> /public/srv/resources/img/img1.png 404 未找到

  1. 甚至像 index.php 和 about.php 这样的链接在 srv1.php 和 solution1.php 页面上也不起作用 - 我得到了同样的 404 错误

请帮助链接路由 提前致谢

对我来说,有时解决这个问题的方法是在路径的开头添加 /,例如 <a href='/srv/srv1.php'>Services</a>

想要 this

但是在您的项目中实现一些框架总是好的。 我使用 CodeIgniter 4 来完成这项工作 - 存在可以处理链接路由的 route.php 文件。

还有更多 php 的框架,例如 Laravel - 使用可以选择任何你想要的