How to href link to a file that's in a folder outside of the folder my file is in?

23,137

When working with directories in a lot of places, such as some command line prompts (shells) and other applications, it's very useful to know that using / at the beginning of the the path will traverse to the home directory from any level, while ../ will traverse to the parent directory of the directory you're in.

For example, if I were creating a link from http://www.example.com/path/to/file.html to http://www.example.com I could simply use <a href="/">Home</a>.

If I wanted to create a link from http://www.example.com/path/to/file.html to http://www.example.com/path/file.html I could use <a href="../file.html">File</a> or <a href="/path/file.html">File</a>.

Finally, if I wanted to create a link from http://www.example.com/path/to/file.html to http://www.example.com/file.html I could use either <a href="../../file.html">File</a> or <a href="/file.html">File</a>.

So for your example you could use either <a href="/tours/tour1.html"> (starting from the root) or <a href="../tours/tour1.html"> (going up one folder and then down into the tours folder).

Share:
23,137
Dom
Author by

Dom

Updated on July 07, 2022

Comments

  • Dom
    Dom almost 2 years

    My files are set up like this:

                                   Root
                                     |
              tours----------------about----------------gallery
                |                    |                     |
           tour1.html            about.html           gallery.html
    

    I want to link the about.html page to the tour1.html page. Is this possible?

    I've tried multiple things and I just can't figure it out. I know that if it were in the same folder I could use <a href="about.html"> and if it was in the root folder I could use <a href="..//about.html"> but neither of those are working.

    • mah
      mah about 8 years
      There are at least two ways to do it, but you've neglected to show what you've tried.... showing what you've tried is a bit of a cardinal requirement here - and also it can lead to you learning something rather than being spoon-fed an answer.
    • mah
      mah about 8 years
      Showing what you tried (by editing your question and putting it there) is even more important now, since according to a comment you left (on a since-deleted answer), what you say you tried does work correctly... so it would be best for you to reproduce your failure and then post what is not working.
  • mah
    mah about 8 years
    This can be posted as a comment but as it does not answer the question, it should not be posted as an answer (and should instead be deleted). However, as there is an answer that has helped you, please "accept" and/or "up vote" that answer, using the links next to it (the check, and the up arrow).