How do I redirect to a parent directory in html

10,554

Solution 1

use relative path in your web page ex: <a href="../file_name"></a>

refer bellow site https://www.w3schools.com/html/html_filepaths.asp

Solution 2

To go up a folder:

<a href="../index.html">my link</a>

Solution 3

In the page1.html you could use relative paths:

<html>
<body>
<a href="../index.html">Go up</a>
</body>
</html>

The link references the upper level in the File System hierarchy.

Hope it helps.

Share:
10,554

Related videos on Youtube

Mister SirCode
Author by

Mister SirCode

Updated on September 18, 2022

Comments

  • Mister SirCode
    Mister SirCode over 1 year

    I want to know if it is possible (and how if it is) to Source to a Past Directory.

    like say I have Index.html, Folder1 > page1.html inside Folder 1

    Can I put a link in page1.html to reach backwards to send you to Index.html??? Im so tired of setting custom URLs to link to Index.html from the base domain...

    My Project is here: Codepen.io

    • mature
      mature almost 5 years
      What server software you use?
    • Mister SirCode
      Mister SirCode almost 5 years
      Im using Codepen -_-
    • Mister SirCode
      Mister SirCode almost 5 years
      Im making a project, Im trying to create a link to send me back 1 directory to index.html codepen.io/SkylerSpark/project/editor/ZpNdMM
    • slhck
      slhck almost 5 years
      Please note that HTML programming questions are off topic here.
    • Mister SirCode
      Mister SirCode almost 5 years
      @slhck Im confused, if html/website questions arent allowed here, Then why are tags and questions about html/websites so common. Also this question has already been answered, there is really no need for any more discussion here.
    • slhck
      slhck almost 5 years
      Please read the description of the HTML tag – it specifically mentions that fact. Also, just because the question is answered doesn't mean it's not off topic. I'm leaving the comment here so that you know what kind of questions to ask here in the future.
  • Mister SirCode
    Mister SirCode almost 5 years
    I know you CAN go backwards in directories, I forgot how to do it, Im sorry but this wont answer my question.
  • raphael75
    raphael75 almost 5 years
    Are you trying to go up a folder? If so: <a href="../index.html">my link</a>.
  • Mister SirCode
    Mister SirCode almost 5 years
    THANKYOU.. yes! thats what I meant
  • raphael75
    raphael75 almost 5 years
    Ok, I'll modify the answer :)
  • Mister SirCode
    Mister SirCode almost 5 years
    One more thing @raphael75 if I do like ../../index.html does that mean it will go backwards 2 directories? or is it like .../ or something?
  • raphael75
    raphael75 almost 5 years
    Each ../ you add makes it go up another level in the folder structure. So to go up 2 levels, ../../myfile.html
  • Mister SirCode
    Mister SirCode almost 5 years
    Thankyou for the answer, but we already have an Answer, for future reference, try not to answer questions with a Green Fill on their tag, or the Check on an answer, as that means the question already has a definite answer, and Only answer in another case if you Know 100% that your answer is more efficient, better, or has more information the other didnt. Thankyou.
  • Javier Reséndiz
    Javier Reséndiz almost 5 years
    I realized I was editing my answer while Raphael was answering too... My mistake!