June 14th, 2008, 11:13 PM
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.
June 15th, 2008, 12:15 AM
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".
June 15th, 2008, 12:34 AM
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.
June 15th, 2008, 01:03 AM
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?
June 15th, 2008, 01:10 AM
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.
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.
June 15th, 2008, 07:07 AM
@Kravvitz and kk5st: thanks both very much. I get the idea now!