假设我有一个网址
http://www.somesite.com/path/to/catalyst/controller
我想将其重定向到
http://www.somesite.com/extra-part/path/to/catalyst/controller
此附加部分应仅在url中,不应考虑用于Catalyst的URL处理。
我发现,我们可以为此继承/覆盖prepare_path方法,但我无法正确使用它。
我找到了这个链接: Catalyst Wiki
但仍需要帮助。
答案 0 :(得分:1)
lib/MyApp.pm
内部我有一个函数prepare_path
,如下所示:
sub prepare_path {
my $c = shift;
$c->maybe::next::method( @_ ) ;
my $base_uri_prefix = $c->config->{base_uri_prefix} ;
my @path_chunks = split m[/], $c->request->path, -1;
if (@path_chunks && $path_chunks[0] eq $base_uri_prefix ) {
shift @path_chunks ;
# Create modified request path from any remaining path chunks:
my $path = join( '/' , @path_chunks ) || '/' ;
# Stuff modified request path back into request:
$c->request->path( $path ) ;
} else {
# Modify the path part of the URI to look as if it had a prefix:
$c->request->uri->path( "$base_uri_prefix/" . $c->request->path ) ;
}
}
在myapp.conf
中定义:
base_uri_prefix extra-part