How do I make links relative to the top directory

Discussion in 'HTML & Website Design' started by Imozeb, Feb 16, 2010.

  1. #1
    How do I make links relative to the top directory instead of using ../file.html

    I want to normally code links can I do this?
     
    Imozeb, Feb 16, 2010 IP
  2. LeetPCUser

    LeetPCUser Peon

    Messages:
    711
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you want to make it relative to the top directory for any file structure the correct way to do it is to implement the backslash "/". Why would you want to do this any other way?
     
    LeetPCUser, Feb 16, 2010 IP
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    monkeyclap, Feb 16, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I want to do this because my folder structure is as follows:

    mainfolder

    1 subfolder: file 1

    2 subfolder: file 2

    3 subfolder: file 3

    I want to include html links from file 3 in file 1 and file 2 but since the links are ../file.html the links in file 3 don't work in both file 1 and 2. Can I fix this to make the links in file 3, file 1, and file 2 all relative to the mainfolder instead of relative to file 3 subfolder?
     
    Imozeb, Feb 16, 2010 IP
  5. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #5
    ../mainfolderfile/subfolder/file.html
     
    monkeyclap, Feb 16, 2010 IP
  6. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #6
    Wrong. Not in all cases.

    If your installation is located in a subdirectory of the main website, say http://www.site.com/blog/ and you want to create a relative link to http://www.site.com/blog/page.html then:

    1. Using <a href="/page.html">Link</a> inside the blog will lead visitors to http://www.site.com/page.html instead of http://www.site.com/blog/page.html

    2. Using <a href="page.html">Link</a> on a blog category page for instance will lead visitors to http://www.site.com/blog/category/page.html instead of http://www.site.com/blog/page.html

    Solution: <a href="./page.html">Link</a> should be used to create a proper link in our case.
     
    Clive, Feb 16, 2010 IP