Mailing List Archive

Directory indexing
Hmm.

I was recently playing around with a server running CERN httpd 3.0, and I
noticed something: When Apache (or NCSA httpd) have a directory, say
/directory/, which does not have an index file and therefore
autogenetates an index, and you request /directory, it redirects your
client to /directory/. CERN doesn't do this, but instead simply builds
the index list with the correctlinks to make it work.

Now, this seemed to me like a sensible thing to do, since it saves a
redirect, and gives the exact same result. So I patched Apache's mod_dir.c
to do this. I'd imagine we'd want to hold off on thinking about this until
the version after 0.8.x, and new features are okay again, but I thought
I'd share it before I forgot about it. Following is a context diff based
on 0.8.10's mod_dir.c. It seems to work when I tried it, although I may
have missed something.

*** mod_dir.c Sat Aug 12 07:33:47 1995
--- mod_dir.c-ak Sat Aug 19 16:13:18 1995
***************
*** 615,622 ****
/* screws up formatting, but some need it. should fix. */
/* escape_html(t2); */
t2 = pstrcat(scratch, t2, "</A>", NULL);
! anchor = pstrcat (scratch, "<A HREF=\"", escape_uri(scratch, t),
! "\">", NULL);
}

if(dir_opts & FANCY_INDEXING) {
--- 615,626 ----
/* screws up formatting, but some need it. should fix. */
/* escape_html(t2); */
t2 = pstrcat(scratch, t2, "</A>", NULL);
! if (!r->path_info || *r->path_info != '/')
! anchor = pstrcat (scratch, "<A HREF=\"", name, "/",
! escape_uri(scratch, t), "\">", NULL);
! else
! anchor = pstrcat (scratch, "<A HREF=\"", name,
! escape_uri(scratch, t), "\">", NULL);
}

if(dir_opts & FANCY_INDEXING) {
***************
*** 762,774 ****

if (r->method_number != M_GET) return NOT_IMPLEMENTED;

- if (!r->path_info || *r->path_info != '/') {
- char* ifile = pstrcat (r->pool, r->uri, "/", NULL);
- table_set (r->headers_out, "Location",
- construct_url(r->pool, ifile, r->server));
- return REDIRECT;
- }
-
/* KLUDGE --- make the sub_req lookups happen in the right directory.
* Fixing this in the sub_req_lookup functions themselves is difficult,
* and would probably break virtual includes...
--- 766,771 ----
***************
*** 784,791 ****
if (rr->status == 200 && rr->finfo.st_mode != 0) {
char *new_uri = pstrdup (r->pool, rr->uri);
destroy_sub_req (rr);
! internal_redirect (new_uri, r);
! return OK;
}

destroy_sub_req (rr);
--- 781,797 ----
if (rr->status == 200 && rr->finfo.st_mode != 0) {
char *new_uri = pstrdup (r->pool, rr->uri);
destroy_sub_req (rr);
!
! if (!r->path_info || *r->path_info != '/') {
! char* ifile = pstrcat (r->pool, r->uri, "/", NULL);
! table_set (r->headers_out, "Location",
! construct_url(r->pool, ifile, r->server));
! return REDIRECT;
! }
! else {
! internal_redirect (new_uri, r);
! return OK;
! }
}

destroy_sub_req (rr);
Re: Directory indexing [ In reply to ]
Noted and saved into my collection of "future feature" patches (which
currently includes David Robinson's draft new Makefiles, Florent's various
patches to content negotiation, and Andrew's "AllowOverride ErrorDocument"
patch)... I suppose I should put these up on hyperreal, but bugfixes first...

rst
Re: Directory indexing [ In reply to ]
We recently had a debate at NCSA about this very topic. We
decided not to remove the redirect to encourage people to
properly reference directories. Remember that if you don't
send a redirect, you at least need to update the location
header to include the trailing slash.

-Beth Frank
efrank@ncsa.uiuc.edu

From Alexei Kosut :
> I was recently playing around with a server running CERN httpd 3.0, and I
> noticed something: When Apache (or NCSA httpd) have a directory, say
> /directory/, which does not have an index file and therefore
> autogenetates an index, and you request /directory, it redirects your
> client to /directory/. CERN doesn't do this, but instead simply builds
> the index list with the correctlinks to make it work.
>
> Now, this seemed to me like a sensible thing to do, since it saves a
> redirect, and gives the exact same result. So I patched Apache's mod_dir.c
> to do this. I'd imagine we'd want to hold off on thinking about this until
> the version after 0.8.x, and new features are okay again, but I thought
> I'd share it before I forgot about it. Following is a context diff based
> on 0.8.10's mod_dir.c. It seems to work when I tried it, although I may
> have missed something.