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;
}




Re: Handler is preventing redirects on missing trailing / ?

2000-10-18 Thread Randal L. Schwartz

> "darren" == darren chamberlain <[EMAIL PROTECTED]> writes:

darren> Clayton Mitchell ([EMAIL PROTECTED]) said something to this effect:
>> 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.

darren> In your handler subroutine, do something like:

darren> return DECLINED if ($r->content_type =~ /directory$/i);

darren> or

darren> return DECLINED if (-d $r->filename);

darren> HTML::Mason has this problem; Locations handled by Mason are all given to
darren> the default handler subroutine, which needs to decline directory requests.

I stole the code for Stonehenge::Pictures partially from some stuff
I saw in the Eagle book, but here's my current meme on that:

use Apache::Constants qw(:common DIR_MAGIC_TYPE);
...
sub handler {
  $R = shift;
  $URI = $R->uri;
...
  if ($R->content_type eq DIR_MAGIC_TYPE) {
return handle_directory();
  } else {
return handle_file();
  }
...
sub handle_directory {
  ## if non-slash URL, send external redirect via mod_dir:
  return DECLINED unless $URI =~ /\/$/;
...

So, I first see if content_type is DIR_MAGIC_TYPE, and then
if it doesn't also end in a slash, I decline, and the nice mod_dir
does all the external redirecting stuff.

(Stonehenge::Pictures is at
.)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: Handler is preventing redirects on missing trailing / ?

2000-10-18 Thread darren chamberlain

Clayton Mitchell ([EMAIL PROTECTED]) said something to this effect:
> 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.

In your handler subroutine, do something like:

return DECLINED if ($r->content_type =~ /directory$/i);

or

return DECLINED if (-d $r->filename);

HTML::Mason has this problem; Locations handled by Mason are all given to
the default handler subroutine, which needs to decline directory requests.

(darren)

> 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__
> 

-- 
I tended to place my wife under a pedestal.
-- Woody Allen