dumb dumb dumb html/relative paths question

Discussion in 'Mac Help/Tips' started by cleo, Aug 3, 2002.

  1. cleo macrumors 65816

    cleo

    Joined:
    Jan 21, 2002
    Location:
    Tampa Bay Area, FL, USA
    #1
    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...?
     
  2. Nipsy macrumors 65816

    Nipsy

    Joined:
    Jan 19, 2002
    #2
    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.
     
  3. cleo thread starter macrumors 65816

    cleo

    Joined:
    Jan 21, 2002
    Location:
    Tampa Bay Area, FL, USA
    #3
    So the first "/" indicates that it should start at the root?

    Excellent... I think this is exactly what I needed. :)
     
  4. Nipsy macrumors 65816

    Nipsy

    Joined:
    Jan 19, 2002
    #4
    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...
     
  5. Hemingray macrumors 68030

    Hemingray

    Joined:
    Jan 9, 2002
    Location:
    Ha ha haaa!
    #5
    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.
     
  6. Rower_CPU Moderator emeritus

    Rower_CPU

    Joined:
    Oct 5, 2001
    Location:
    San Diego, CA
    #6
    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.
     
  7. cleo thread starter macrumors 65816

    cleo

    Joined:
    Jan 21, 2002
    Location:
    Tampa Bay Area, FL, USA
    #7
    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
     

Share This Page