dumb dumb dumb html/relative paths question

cleo

macrumors 65816
Original poster
Jan 21, 2002
1,186
0
Tampa Bay Area, FL, USA
Nothing to do with Macs, except that I'm using one to design a website... :D

I need help with relative paths. OK, so I know that if I have a document http://www.mydomain.com/index.html and I want to call an image http://www.mydomain.com/images/logo.gif I can just do src="images/logo.gif".

But what if I have a document http://www.mydomain.com/news/index.html and I want to use the same image? How do I indicate that "images" is a branch off the base directory, not the current one?

I think it involves periods or homes or roots or something...?
 

Nipsy

macrumors 65816
Jan 19, 2002
1,009
0
Some hints:

Relative paths can cause some issues with future restructuring. Absolute paths can cause some issues with portability.

If you can, use root relative paths.

To answer your question

Absolute:
<img src="http://www.mydomain.com/images/logo.gif">
Relative:
<img src="../images/logo.gif">
Root-Relative:
<img src="/images/logo.gif">

The key to root relative is that it always begins at the site root folder, and tracks from there. Since everything is in the root folder, you can always create a root-relative path (some cgi-bins excepted).

The dowside to using plain relative is that if you move /news/index.html later into /news/archives/index.html, the link will break.

The downside to absolut paths is that the full http:// request generates needless overhead.
 

Nipsy

macrumors 65816
Jan 19, 2002
1,009
0
Originally posted by cleo
So the first "/" indicates that it should start at the root?

Excellent... I think this is exactly what I needed. :)
Yep,

Leading / indicates site root

name/name2/ indicates start where you are, up to name, up to name 2

../../name indicates go down, go down again, go up to name.

Works just like OSX...
 

Hemingray

macrumors 68030
Jan 9, 2002
2,913
25
Ha ha haaa!
Originally posted by Nipsy
The dowside to using plain relative is that if you move /news/index.html later into /news/archives/index.html, the link will break.
At times like that it's handy to have a program like Adobe GoLive that will automatically manage your links and update every page that references that link to the new location.

By default GoLive uses all relative links.
 

Rower_CPU

Moderator emeritus
Oct 5, 2001
11,111
0
San Diego, CA
I'd advise you to stick with document relative links, rather than root relative.

It's a personal preference of mine, but in your case it would probably help you avoid confusion as to how your site is laid out by your ISP.
 

cleo

macrumors 65816
Original poster
Jan 21, 2002
1,186
0
Tampa Bay Area, FL, USA
Rower -

Yeah, I figured that out REAL fast. My "root" appears to be about 17 layers deep... annoying as all get-out. Also, because a lot of these docs use PHP includes, things were just getting too difficult. I decided just to put everything in the main directory. If whoever comes after me in managing the site wants more organization, let them do it :D