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.
Related videos on Youtube
Author by
Mister SirCode
Updated on September 18, 2022Comments
-
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 almost 5 yearsWhat server software you use?
-
Mister SirCode almost 5 yearsIm using Codepen -_-
-
Mister SirCode almost 5 yearsIm 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 almost 5 yearsPlease note that HTML programming questions are off topic here.
-
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 almost 5 yearsPlease 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 almost 5 yearsI know you CAN go backwards in directories, I forgot how to do it, Im sorry but this wont answer my question.
-
raphael75 almost 5 yearsAre you trying to go up a folder? If so: <a href="../index.html">my link</a>.
-
Mister SirCode almost 5 yearsTHANKYOU.. yes! thats what I meant
-
raphael75 almost 5 yearsOk, I'll modify the answer :)
-
Mister SirCode almost 5 yearsOne 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 almost 5 yearsEach ../ you add makes it go up another level in the folder structure. So to go up 2 levels, ../../myfile.html
-
Mister SirCode almost 5 yearsThankyou 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 almost 5 yearsI realized I was editing my answer while Raphael was answering too... My mistake!