When I code my website, on my local computer i can use
<a href="index.html">blablabla</a>.
However, I also can see this type of thing on other places as
<a href="/index.html">blablabla</a>.
I am not sure what I will need when my site goes live. If I try to do this on my local computer, it doesn't understand it. My question is, if I post my site up like this, will it work?
Ok, if I have all of the files of my site in the root directory that the main index.html file is located in, will it work when it is being hosted?
Historically, a trailing slash marked a directory and a URL without a trailing slash at the end used to mean that the URL was a file. Today, however, trailing slashes are purely conventional, and Google does not care whether you use them; as long as you're consistent.
If your site has a directory structure, it's more conventional to use a trailing slash with your directory URLs (for example, example.com/directory/ rather than example.com/directory ), but you can choose whichever you like. Be consistent with the preferred version. Use it in your internal links.
The addition of a slash at the end of a URL instructs the web server to search for a directory. This speeds the web page loading because the server will retrieve the content of the web page without wasting time searching for the file.
As a matter of modern spec, yes, it is permissible to skip the slash, contrary to what the accepted answer here claims.
If you do not use a slash, the link will point to index.html
in the same folder as the page the link is on.
For example, if you have a link to index.html
on the page www.example.com/page2.html
then the link will take you to www.example.com/index.html
. If you include a slash, it will do the same thing.
However, if the link is in a page in a subfolder, like www.example.com/projects/page2.html
, then the first link will take you to www.example.com/projects/index.html
while the second link will still take you to www.example.com/index.html
.
The slash denotes the "web root."
Note that these are still considered "relative" links: they refer to a resource on the same server, regardless of the server's name. If your domain name changes or you upload it to another server, relative links will still work provided they have the same folder structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With