2

I am partially through implementing the functionality of SimpleHTTPServer.py in Scheme. I am having some good fun with HTTP request/response mechanism. While going through the above file, I came across this- " # redirect browser - doing basically what apache does" in the code".

Why is this redirection necessary in such a scenario?

gliptak
  • 3,592
  • 2
  • 29
  • 61

2 Answers2

3

It simplifies things to treat the trailing / as irrelevant when the user does a GET on a directory, so that (say) http://www.foo.com/bar and http://www.foo.com/bar/ have exactly the same effect. Simplest (though not fastest, see Souders' books;-) is to have the former cause a redirect to the latter.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • ah, that was simple.. I will wait for while if any one got any thing to share. Thanks! –  Jul 21 '09 at 16:52
3

Imagine you serve a page

http://mydomain.com/bla

that contains

<a href="more.html">Read more...</a>

On click, the user's browser would retrieve http://mydomain.com/more.html. Had you instead served

http://mydomain.com/bla/

(with the same content), the browser would retrieve http://mydomain.com/bla/more.html. To avoid this ambiguity, the redirection appends a slash if the URL points to a directory.

balpha
  • 50,022
  • 18
  • 110
  • 131