0

我有一个像这样的文件结构:

Admin/index.php
index.php
master.php
site.js

的简化版本master.php

<html>
    <head>
        <script src="site.js"></script>
    </head>
    <body>
        <?php echo $content ?>
    </body>
</html>

的简化版本index.php

<?php ob_start(); ?>
Lorem ipsum
<?php
    $content = ob_get_contents();
ob_end_clean();
    include("master.php");
?>

的简化版本Admin/index.php

<?php ob_start(); ?>
Lorem ipsum
<?php
    $content = ob_get_contents();
ob_end_clean();
    include("../master.php");
?>

index.php工作得很好,但是在Admin/index.php,它试图site.jsAdmin文件夹中找到......

我可以使用/absolute/path/to/site.js,但站点的不同实例在不同的 url 下运行(例如http://mysite.com/Instance1/Admin/index.php等...)

那么我该如何解决这个问题,以便它site.js在其中的文件夹中查找master.php,而不是在页面文件夹中查找,包括 master.php

4

1 回答 1

2

你可以使用 <base href="http:/site.com/" />

把它放在 HTML 的头部(在 之间<head> and </head>)。

<base>标记指定文档中所有相对 URL 的基本 URL/目标。

因此,如果您将其设置为http://yoursite.com/instance1/并将您的 js 设置为 script.js ,它将从http://yoursite.com/instance1/script.js获取它。

于 2012-09-11T14:35:15.470 回答