Click to See Complete Forum and Search --> : linking to root directory


cobalt
04-12-2005, 08:59 AM
What is the best practice for linking to files or directories in the root directory of your site even if you are already in the root directory? I have to change a lot of links in my personal development folder and don't want them to break when they are moved to the root of the actual development directory.

Thanks!

WoD
04-12-2005, 09:19 AM
Use a base href: http://www.codeave.com/html/code.asp?u_log=5028

Use a leading slash: /mydir/myfile.gif

Use your full path: http://www.mysite.com/mydir/myfile.gif

The best method? I have no idea.

cobalt
04-12-2005, 09:29 AM
I've tried using ../directory/page.html from a directory under the root, but am afraid that will break once I move it up to the root directory.

WoD
04-12-2005, 10:56 AM
It will. I think /directory/page.html works also - although I seem to remember a bug in Firefox with it.

David Harrison
04-12-2005, 11:17 AM
When referencing things, like in the href of links and the src attribute of images etc.
/ = the root folder
./ = the current folder
../ = one level up the folder tree

So using a leading / would be the best option, I do not recommend using a <base> as it can lead to difficulties later.

cobalt
04-12-2005, 12:04 PM
Thanks, that's exactly what I needed to know.