I have a file structure like so:
Admin/index.php
index.php
master.php
site.js
Simplified version of master.php:
<html>
<head>
<script src="site.js"></script>
</head>
<body>
<?php echo $content ?>
</body>
</html>
Simplified version of index.php:
<?php ob_start(); ?>
Lorem ipsum
<?php
$content = ob_get_contents();
ob_end_clean();
include("master.php");
?>
Simplified version of Admin/index.php:
<?php ob_start(); ?>
Lorem ipsum
<?php
$content = ob_get_contents();
ob_end_clean();
include("../master.php");
?>
index.php works just fine, but in Admin/index.php, it tries to find site.js in the Admin folder…
I could use /absolute/path/to/site.js, but different instances of the site are running under different urls (such as http://mysite.com/Instance1/Admin/index.php etc…)
So how can I fix this so that it looks for site.js in the folder that master.php is in, and not the folder of page including master.php?
You could use
<base href="http:/site.com/" />put it in the head section of your HTML (between
<head> and </head>).The
<base>tag specifies the base URL/target for all relative URLs in a document.So if you set this to http://yoursite.com/instance1/ and you set your js to script.js it will fetch it from http://yoursite.com/instance1/script.js.