blablabla. However, I can also s...">

Do I need slashes before links?

When I code my site, on my local computer I can use

<a href="index.html">blablabla</a>. 

However, I can also see this type of thing in other places since a href="/index.html">blablabla</a>. I'm not sure what I will need when my site is live. If I try to do this on my local computer, he will not understand this. My question is, if I publish my site like this, will it work?

Well, if I have all the files on my site in the root directory where the main index.html file is located, will it work when it is hosted?

+6
source share
1 answer

If you do not use a slash, the link points to index.html in the same folder as the page on which the link is located.

For example, if you have a link to index.html at www.example.com/page2.html , the link goes to www.example.com/index.html . If you include a slash, it will do the same.

However, if the link is on a page in a subfolder, for example www.example.com/projects/page2.html , then the first link will lead you to www.example.com/projects/index.html , and the second link will still lead you to www.example.com/index.html .

The slash marks the web root.

Note that they are still considered โ€œrelativeโ€ links: they refer to a resource on the same server, regardless of the server name. If your domain name changes or you upload it to another server, relative links will work if they have the same folder structure.

+6
source

All Articles