>我有两个站点,一个存储在服务器的根目录中,另一个存储在子文件夹中,如下所示。
SITE ONE
ROOT/index.php
ROOT/assets/includes/header.php - contains styles and scripts
SITE TWO
ROOT/SUB-FOLDER/index.php
ROOT/SUB-FOLDER/assets/includes/header.php - contains styles and scripts
我正在使用 PHP include 来包含外部文件,其中第一个站点使用以下代码工作正常,但第二个站点没有:
include($_SERVER["DOCUMENT_ROOT"] . '/assets/includes/header.php');
您能否帮助我为存储在子文件夹中的站点实现类似的结果。
提前谢谢。
将包含链接更改为:
include('assets/includes/header.php');
并添加
<base href="http://example.com/SUB-FOLDER">
标记到包含页面的标题解决了我的问题。