Href not linking to relative file

When I click on link, it says file can not be found despite folder and file being in the same folder.

I only see href12.html in the folder. Where is h.html?

Also in that Case the real position of the file is not important. If you want to call the file like this it needs to be in the root folder of your Webservers web folders. We do not know where this is

1 Like

h.html is in Href folder.

I want to understand

If I’m linking the file of sub folder to the file of main folder, It will not work? and can only do it in reverse roles?

Then you need to come out of that folder using ../ and then you will be at the same level as the file you want to reach.

<a href="../Href12.html">

you need to add the …/ to get from sub to main?

and you don’t need to add …/ if main file is linking to sub file?

It depends on how you’re navigating.

  • If starting from the root of a site, start with /
  • If going up a level, then you start with …/
  • If going down a level then use the folder name first.

Example

/
  --folder
     a.html
     -- sub-folder
         b.html
         -- sub-sub
             c.html

From a.html to get to b.html, you can use

  • sub-folder/b.html
  • /folder/sub-folder/b.html

From b.html to get to c.html, you can use

  • /a.html
  • /folder/a.html

From c.html:

  • to get to b.html, use …/b.html
  • to get to a.html, use …/…/a.html

technically, you can use ./ to go in the same folder, but most skip that because it’s unneeded.

2 Likes

When I open my main file from VScode, it pops up some library. but when I open the main file from the folder, it pops up the website. why

I understand now, ty. can you answer my question that I sent to paul

I didn’t see it as a question but a statement.:slight_smile but basically yes.

…/ takes you up one directory. …/…/ would take you up two directories and so on.

To drill down once you just use the foldername/filename.html or two levels down from where you are folder1/folder2/filename.html.

Relative urls are based from where you are.

1 Like

I’m in Tennessee but my relatives are in Georgia. So what should change?

2 Likes

When you are both in the USA you are lost anyway :rofl:

3 Likes