Solution 1 :

If you are using MySQL, it will look something like this: localhost/folder/pages/task-form.php
Simply use as many ‘../’ as necessary to back out directories until you get to the destination that contains the main folder. in my example mentioned above, the file is 2 folders deep, so it requires 2 “../”
For this use:
<li><a href="../../folder/pages/task-form.php">Post Task</a></li>
For your example:
<li><a href="../pages/task-form.php">Post Task</a></li>

This will always take you to the main folder, then go to the destination of the file, even if youre already at it.
The way you were doing it was simply opening the destination folder, and the file again, while still being at the folder, thus creating a duplicate of the folder.
Important: You must use as many “../” as the deepest file you are accessing if it has a header.php linked to it. You can use 10 of “../” even if youre not 10 deep. It cant back out more than the most containing folder.

Problem :

if i am at the current address: “pages/tasks.php”
then click a link that has:
<li><a href="./pages/task-form.php">Post Task</a></li>
my address becomes:
“/pages/pages/task-form.php”
i understand its because it is opening that link on top of my current folder depth. I know I can put all of the pages in the same folder, then delete the “./pages/”. If I do that, then I cant access another page in a different folder. But what if I want to be able to change directories with pages, or stay in the same folder at the same time? I am using a header.php template for all pages.

Comments

Comment posted by stackoverflow.com/questions/11094776/…

Take a look at

Comment posted by Jeremy Harris

The easiest way to fix it is use absolute paths instead of relative paths. Change

By