Re: Handler is preventing redirects on missing trailing / ?

2000-12-21 Thread Doug MacEachern

On Wed, 11 Oct 2000, Clayton Mitchell wrote:
 
 I then noticed that URI's of directories lacking a trailing '/' were not
 being redirected in the browser and so relative links started to break.

since your PerlHandler is handling the directory, you need to manage that.
mod_autoindex and mod_dir both do it themselves, in different ways, here's
mod_dir:
if (r-uri[0] == '\0' || r-uri[strlen(r-uri) - 1] != '/') {
char *ifile;
if (r-args != NULL)
ifile = ap_pstrcat(r-pool, ap_escape_uri(r-pool, r-uri),
"/", "?", r-args, NULL);
else
ifile = ap_pstrcat(r-pool, ap_escape_uri(r-pool, r-uri),
"/", NULL);

ap_table_setn(r-headers_out, "Location",
  ap_construct_url(r-pool, ifile, r));
return HTTP_MOVED_PERMANENTLY;
}




Handler is preventing redirects on missing trailing / ?

2000-10-11 Thread Clayton Mitchell

I installed a handler as such:


httpsd.conf:
-
PerlModule Tofu::Tofuhandler
Location /userfiles 
SetHandler perl-script
PerlHandler Tofu::Tofuhandler
/Location

Location /
AddHandler perl-script *.html
PerlHandler Tofu::Tofuhandler
/Location

I then noticed that URI's of directories lacking a trailing '/' were not
being redirected in the browser and so relative links started to break.

As a w/o I installed a TransHandler listed below to modify the URI.   It
seems like I am re-inventing the wheel here and so I assume I did something
wrong to get to this point?  
Thanks for any advice.


package Tofu::Tofugruff;

#use Apache::Constants qw(:common);
use Apache::Constants qw(:response);

use strict;


 sub handler {
my $r = shift;
my $f = $r-document_root.$r-uri;
my $uri = $r-uri;
if ( -d $f  $f !~/.*\/$/ ) {
   # A directory that doesn't end in a '/'
   $uri.='/';  # fix it
   $r-err_header_out("Pragma", "no-cache");
   $r-header_out("Location" = $uri );
   $r-status(REDIRECT);
   return DECLINED;
}
return DECLINED;
 }

1;
__END__