Search code examples
javascriptdirectoryparent

Parent Directory '../' going up two directories


I am very confused.

I have been testing a site I am building on one server, and on that server I have a link to a javascript file. On said server I link to the file with '../js/javascript.js' and the file loads properly. On another server I just switched to, if I use the same link the file does not load. I look at firebug and see it seems that '../' is going up two directories and returning a 404 error.

I have fixed the path on the new server, but I am confused about the inconsistency.

I believe it has to do with the fact that I call the javascript in my header.php file, which is in a directory called inc. however the index.php where I include my header.php is in the root directory. But, I don't understand why on one server it references from the root and on the other it references from inside the inc directory.

site/
    index.php
    js/
       javascript.js
    inc/
       header.php

Solution

  • It does not matter where header.php exists, because it gets included in index.php before the page is delivered to the browser. So any <script src="..."> tags will be relative to index.php. So, your HTML for including the js file should be:

    <script src="js/javascript.js">
    

    No ../! Not sure why it worked on the old server, but it definitely won't work on the new one as you've described it.