age*_*ert 1 php relative-path include
我正在设置我的网站以使用该include()
语句来标准化页眉,页脚和导航等内容,例如
include('header.php);
但是,当我对两个不同目录中的页面使用相同的头文件时,header.php
break中包含相对链接,例如:
header.php文件
<a href="images/dog.jpg">
index.php
include('header.php);
成为
<a href="images/dog.jpg">
这是有效的,因为这是index.php文件中dog.jpg的正确路径.
animals/canine.php
include('header.php);
变成了
<a href="images/dog.jpg">
这不起作用,因为不存在animals/images/dog.jpg.
所以,我的问题是,当header.php被包含在内时,我可以在header.php文件中更改哪些内容可以定制ur.to dog.jpg以及index.php和animals/canine.php中的url?
更改包含以使用绝对路径:
<a href="/images/dog.jpg">
Run Code Online (Sandbox Code Playgroud)
这样,它们将基于您网站的根目录,并始终指向正确的文件夹.