Search code examples
phpreferenceincluderequire-oncehome-directory

Can't reference non php files from another folder?


I have a site at https://fixitprobid.com, and in the home directory I have 3 folders: css, js, and diy. Each lead to their respective types of files. so css/styles.css, js/utility.js, diy/install-a-dryer.php (there are many more files and folders than that, but that's the general structure)

How can install-a-dryer.php reach styles.css and utility.js?

Currently, install-a-dryer.php has require_once("../initialize.php"); This should leave the diy folder and end up in the home directory. right?

Then initialize.php has require_once("header.php"); (in the home directory)

header.php has require_once('meta.php'); (in the home directory)

meta.php has <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script src="js/utility.js"></script>

It seems to think that all those things are now in the diy folder, since they are included in it. even though I used ../ to get out of it. So they don't work.

I get errors like this enter image description here

How can I change the install-a-dryer.php or initialize.php files to make them all work? Note that I can only edit those two files. Editing all the individual links is not an option. There may be thousands of references and I won't find all of them, even if there is a way to do it right.

Thanks :)


Solution

  • Because css and js folders are located at the root of your site, so add a slash at the beginning of the path:

    <link href="/css/styles.css" rel="stylesheet" type="text/css" />
    <script src="/js/utility.js"></script>