#1
  1. Classical Computing
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    893
    Rep Power
    102

    A question about relative links to folders


    I'm exploring the formalities of relative links to folders.

    In particular, I've noticed that, whereas a link like href="folder/page.html" must vary depending on where the referring page is located in the site (eg, another referring page might have href="../../folder/page.html"), a link like href="/folder/" can remain the same no matter what page it appears in, and will always land you on the index page in that folder.

    Using the same link from anywhere in the site (say on a menu that appears on every page) is really handy, but I was just wondering what the specific rules are in relation to this kind of usage, as I'm new to this and am trying to be careful not to fall into an HTML crevasse!

    Can anyone can cite some official guidelines for this href="/folder/" usage?

    Thanks for any suggestions.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    This is the explanation I gave the last time I answered a question about file paths:

    In a file path or URL "./" means the current directory, "../" means the current directory's parent directory, and a relative path or URL starting with just a slash ("/") refers to web root (or the root file system directory for non-URL paths). You can do something like "../../example.ext" and "../../../example.ext".
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. Classical Computing
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    893
    Rep Power
    102
    OK, thanks for that. So why does "/folder/" lead to the same folder no matter how deep into the site you put it?

    If you look at the Happy Cog site, for example, their menu is repeated on every page, folders withinin folders, but still the links are always just "/design/" etc.
    Last edited by Arem; June 15th, 2008 at 07:10 AM.
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    So why does "/folder/" lead to the same folder no matter how deep into the site you put it?
    Because it's relative to web root, which is the top level folder you can get to via the web server. It doesn't matter how many levels you go below web root, a path relative to it will not change based on how many levels you are below it. Does that make more sense?
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. Thanks Johnny Hart (BC) R.I.P.

    Join Date
    May 2003
    Location
    Dallas
    Posts
    5,268
    Rep Power
    1956
    Because / is always the doc root. If your doc root is /var/www on the server, then / is always based on /var/www, and /folder/ refers to [/var/www]/folder/. In the OS, / is the root directory, so /var/ is a sub-directory of root, and www is a sub-directory of /var. The server treats the doc root like the OS treats the actual root. / is the [doc]root, and everything is descended from [doc]root.

    cheers,

    gary
    There are those who manage to build a web site without knowing what they're doing; thereby proving to themselves they do, indeed, know what they're doing.

    My html and css workshop, demos and tutorials.
    Ask a better question, get a better answer.
  10. #6
  11. Classical Computing
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    893
    Rep Power
    102
    @Kravvitz and kk5st: thanks both very much. I get the idea now!

IMN logo majestic logo threadwatch logo seochat tools logo