Forum Moderators: phranque
as though myfile.php was there and was a "soft link" to
/myfile.php (in the root directory). In other words, I want to keep one copy of myfile.php in the root directory, and have any other requests for myfile.php from other subdirectories reference the one copy.
I need it to behave like a soft link, though, because the PHP file in question references some other files in the current working directory - which should result in different output depending on which directory the file is in. I tried using a basic RewriteRule statement, but that just serves the copy from the root directory as though root is the current working directory.
Does this make sense? Can anyone help me out with how I might do this?
Thanks in advance.
$file = 'siteInfo.js';
if (is_readable($file) == false) {
die("$file doesn't exist or we can't read it!");
}
$subdata = file_get_contents($file);
Additionally, the PHP file looks for subdirectories which also contain a 'siteInfo.js' file, and then links to a "links.php" file in each of those subdirectories. (Which is supposed to be a soft link of this same php file... kind of a recursive thing... make sense?)
$output = shell_exec("ls -l */siteInfo.js");
$match = preg_match_all("/\S*\//", $output, $matches);
foreach ($matches[0] as $subdir) {
echo "<a href=\"${subdir}links.php\">${subdir}links.php</a> <br />";
}
$last_slash_pos = strrpos( $_SERVER['SCRIPT_NAME'], '/' ) +1);
$rel_path = substr($_SERVER['SCRIPT_NAME'], 0, $last_slash_pos);
Then, you can just add the $rel_path variable to you links in your script:
echo '<a href=' . $rel_path . 'your_soft_link.php';
I figured out a solution; somewhat of a workaround but it is doing the trick. In the RewriteRule statement you can do a pattern capture - I am capturing the actual path, then appending it as a query string. So /subdir1/subdir2/myfile.php gets redirected to /myfile.php?PATH=/subdir1/subdir2. I had to modify my php script to pick up the $_GET['PATH'] value and prepend it to the links that the page builds. It is kind of kludgey but so far it is working.