[ROOT LINK] Referring to root instead of ../

Discussion in 'PHP' started by gigafare, Jul 23, 2007.

  1. #1
    Hi

    I have a site structure, not using a cms, in which i'd like to link to my root index, from within different directories.

    Now is there a script like <? root ?> that i can paste before every link thus re-using that link wherever in the site?
    something like <a href="<? root ?>/services"> for EVERY directory no mather how deep in the site structure instead of using ../services or ../../../services,...

    Hope it's clear enough!
     
    gigafare, Jul 23, 2007 IP
  2. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Any reason you can't use an absolute path as in <a href="/services"> ? That will point to yourdomain.com/services no matter where it's called from.
     
    mrmonster, Jul 23, 2007 IP
  3. gigafare

    gigafare Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would prefer to put all my links in one file called links.php, and include them.
    But those links won't work when there accessed in a subdirectory far away will they?
     
    gigafare, Jul 23, 2007 IP
  4. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #4
    <a href="/services"> will work anywhere as it's an absolute path and doesn't care what directory it's in, it will always point to "domain.com/services"
     
    mrmonster, Jul 23, 2007 IP