Search code examples
htmldirectoryhref

href="../" links to root instead of parent directory


I'm writing a simple web server and doing some directory traversals, and in each directory I include a link to the parent directory for going back up.

However, regardless of my depth in the directory tree, when I create that parent link (using href="../" in my link), it goes right back to the root.

For example:
- I am in localhost:2345/dir1/dir2/dir3/dir4
- HTML page displays links to files & directories in dir4, including parent
- "parent" is linked (<\a>) with (href="../")
- Click "parent" --> directed to localhost:2345/


Solution

  • Here is a couple of things I would try to do: (1) Check web server redirection settings (2) Does the web server require file extension (ex. .html .htm) to properly load the page? You can probably try ../index.html if the root file of the parent directory is named index.html.