[Techtalk] directory handling with apache server
johnc+linuxchix at kirriwa.net
Mon Oct 27 10:51:15 EST 2003
On Sun, Oct 26, 2003 at 04:48:48 -0800, Berenice Chong wrote:
> How does apache know that a requested url is a directory? Is it
> because of the trailing slash at the end? The FAQ says trailing
no. you can give it a directory url without a trailing slash and it'll
still work. the system call stat() can be used to find out whether a
give path is a file or directory (or symlink or socket or device or
fifo). see the stat man page for more detail.
> slashes are needed for relative URLs to work properly, but I don't
> understand why.
that's within a document, and the slash is needed for the browser to
build the correct url. if you type in the url:
the server (apache) knows that /john is a directory, but the browser
doesn't. a relative url within /john/index.html, e.g.:
has to be converted into an absolute url by the browser. without a
trailing slash, it will strip "john" and add "photos/index.html",
giving "http://kirriwa.net/photos/index.html" which is incorrect, but
the browser doesn't know that because it has no idea that "/john" is a
fortunately, apache sends a redirection to the browser when "/john" is
[johnc at dropbear ~]$ telnet kirriwa.net 80
Connected to kirriwa.net.
Escape character is '^]'.
GET http://kirriwa.net/john HTTP/1.0
HTTP/1.0 301 Moved Permanently
Date: Sun, 26 Oct 2003 22:44:52 GMT
[rest of reply snipped]
the browser then fetches the new url, this time with a trailing slash,
and can then build any relative urls correctly because it now knows that
"/john" is a directory.
hope this helps.
whois !JC774-AU at whois.aunic.net
GPG key id: 0xD59C360F
More information about the Techtalk