1

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 :)

ioan
  • 295
  • 2
  • 7
  • 23
  • Your relative link is relative to the client url. You call your script in the `/diy/` folder, so the path becomes `/diy/css/styles.css`. Your require include paths have no bearing on this. – Progrock May 12 '18 at 21:06

1 Answers1

1

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>
camelsWriteInCamelCase
  • 1,655
  • 1
  • 10
  • 15
  • I tried that earlier, and i tried it again, but it doesn't seem to load everything. Mainly styles.css isn't loading. or at least i don't see it when I inspect elements and the page looks messed up. There are other styles coming from the same css/ folder which work, but not the main styles.css file. And I know the file works because any pages outside of the diy folder are fine. – ioan May 12 '18 at 16:40
  • It can be because of CSS caching. Try to change href to _/css/styles.css?version=some_number_. Read more [here](https://stackoverflow.com/questions/118884/how-to-force-browser-to-reload-cached-css-js-files). – camelsWriteInCamelCase May 12 '18 at 17:30
  • Yeah i think some files connected, but not all, and not the main styles.css file since I don't see it when I inspect element. I tried to clear cache on my browser and refresh with ctrl-f5. But even if it worked there will probably be random references and images that will need to have the slash as well. I was hoping I would only need to change the code in the files that are in the diy folder, since those are the ones in a different path. – ioan May 13 '18 at 23:15