While studying HTML tutorial on HTML Links Chapter on w3schools.com I saw following sentence:
Without a forward slash on subfolder addresses, you might generate two requests to the server. Many servers will automatically add a forward slash to the address, and then create a new request.
I didn't get the meaning of how two request can be passed if trailing slash is missing in the URL mentioned in href attribute of anchor tag?
Consider you have a URL like this:
Since in many servers, the
directory
can be accessed without a trailing slash, but it is good to have one, right? So, the server, generally redirects the client to put the slash in the end.Why two requests?
See the below conversation between the client and server.
http://example.com/myfolder
.http://example.com/myfolder/
,HTTP 302 Found
- This is a temporary redirect.http://example.com/myfolder/
.HTTP 200 OK
- Here's your content.So there are two requests from the client to the server. Hope you understand.
ps: Please do not use W3Schools, there are lot more better resources.
A web server receiving a request for
/foo
may look at it and see that itsfoo
is actually a folder, and decide that the actual address for this folder is/foo/
. So it will respond with a302
redirect to the client and tell it to fetch/foo/
instead:GET /foo
302 Found, Location: /foo/
GET /foo/
200 OK, content...
Whether the server does this or not depends on your server. Ultimately you should always use the actual URL of items in your links, don't rely on a server to "fix it" implicitly for you.