Skip to content Skip to sidebar Skip to footer

What's The Actual Meaning Of 'two Requests To The Server' In This Context?

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 th

Solution 1:

Consider you have a URL like this:

http://example.com/myfolder/

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.

  1. Client Request #1: I am requesting you http://example.com/myfolder.
  2. Server Response #1: I want you to go to http://example.com/myfolder/, HTTP 302 Found - This is a temporary redirect.
  3. Client Request #2: Ah, OKay! I am requesting you http://example.com/myfolder/.
  4. Server Response #2: Sure, here you go. 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.


Solution 2:

A web server receiving a request for /foo may look at it and see that its foo is actually a folder, and decide that the actual address for this folder is /foo/. So it will respond with a 302 redirect to the client and tell it to fetch /foo/ instead:

  1. browser to server: GET /foo
  2. server to browser: 302 Found, Location: /foo/
  3. browser to server: GET /foo/
  4. server to browser: 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.


Post a Comment for "What's The Actual Meaning Of 'two Requests To The Server' In This Context?"