Sonya Lambert
Sonya Lambert

Reputation: 47

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

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.

Upvotes: 0

Views: 28465

Answers (3)

muuku
muuku

Reputation: 1

There are different methods

You could use ../ each time to go back one step in your directory and then target your file.

Or(if you are familiar with node/express or ejs templates) you could directly target /filename as you specified in your app.get("/filename",.....

Upvotes: -1

Dom
Dom

Reputation: 2325

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).

Upvotes: 9

Sonya Lambert
Sonya Lambert

Reputation: 47

Thank you everyone for the suggestions. I tried out an absolute path instead of a relative path and it worked, so I'm just going to work with that instead.

Upvotes: -4

Related Questions