我有一个标准的PhP网站,其中包含3个文件,并且每个文件都有一个样式表,都位于样式文件夹中。 这些文件是:
header.php
index.php
footer.php
我已经做到了这一点,因此我可以根据需要轻松地在任何页面上调用页眉和页脚。
我的问题是,如果我在URL的末尾添加一个正斜杠,它会更改基本文件夹,导致找不到样式表文件,如附件中的图像所示。 基本上,它开始在索引文件夹中寻找“ style / header.css”,该文件夹甚至不存在,因此,如果我正确理解的话,将找不到CSS文件。我有一个htaccess文件,用于从URL中删除.php扩展名,但我尝试不使用它,但得到了相同的错误。
我已经读到,使用绝对路径会有所帮助,但这不会在任何地方托管,因此我不确定要如何帮助我的情况。
这是我标头上的head标签,其中包含所有链接
<head>
<meta name="description" content="website" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="img/logo/logo3.png" type="image/x-icon">
<link rel="stylesheet" href="style/header.css" />
<link rel="stylesheet" href="style/extras.css" />
<link rel="stylesheet" href="style/style.css" />
<link rel="stylesheet" href="style/footer.css" />
<script src="js/header.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="https://kit.fontawesome.com/b076d05399.js"></script>
</head>
我只是使用这些代码相应地调用页眉和页脚。
<?php
require_once "header.php";
?>
content
<?php
require_once "footer.php";
?>