Redirects and trailing slashes

When you select a URL that points to a directory on a webserver it should have a trailing slash. That is because that is part of the definition of HTTP and is needed to be that way so that browsers can work out what relative URLs are relative to.

So what goes on behind the scenes when someone specifies a URL for a directory without the trailing slash, like ?

  1. Browser contacts and asks to get /ccc .
  2. The server at notices that there is no normal file with that path and strictly speaking would have the right to say, "Document not found".
  3. But being a nice friendly cooperative sort of server, it will check to see if there is a directory by that name. It finds one.
  4. It can't just supply the document for that address, since then the browser would think that it was looking at a file instead of a directory and would get all of its relative URLs wrong.
  5. So the server tells the browser that it has requested an incorrect location and that it should request This is called a "Redirect".
  6. The browser says OK. And makes a new connection to and asks to get /ccc/
  7. The server sees that it does have a directory by that name and supplies the browser the normal stuff it does for a directory request.

    That is usually a directory listing or the contents of a file called index.html or file of some other distinguished name.

previous contents next

Jeff Goldberg