[cgiapp] can not redirect to upper level url ?

Clayton Scott clayton.scott at gmail.com
Wed Sep 3 07:12:05 EDT 2008


On Tue, Sep 2, 2008 at 10:49 PM, Silent <silent2600 at gmail.com> wrote:

> when the app run with URI like "/cgi-bin/app.cgi/news/1024"
> and I want to redirect to "/cgi-bin/app.cgi/home", (for news id 1024 may not found)
>
> I use $cap->redirect('../home');          # I always think this will work
>
> but I only got redirect to "/cgi-bin/app.cgi/news/home",        and this
> will got a endless loop

It is doing exactly what you told it to do. You need a '../' for each
path part after
app.cgi.

> could anyone tell me a better method ? not use absolute path or
> CAP::P::Forward maybe I need to caculate the new path by $ENV{xxx}

The best method is to use an absolute path like you suggested:

# code not tested
my $home_url = $cap->query->url( -absolute => 1 ) . '/home' );
$cap->redirect( $home_url );

or if you absolutely must use a 'relative' url:

my @levels = split /\//, $cap->query->path_info;

my $home_url =  $cap->query->url(-absolute => 1) . '../' x @levels . 'home';
$cap->redirect( $home_url );

I'd still go with option one (absolute url)

HTH,
Clayton
-- 

Clayton Scott
clayton.scott at gmail.com


More information about the cgiapp mailing list