[Catalyst] RFC for plugin to strip script name from URI;
plugin name + code review
Ashley
apv at sedition.com
Sun Mar 30 07:27:39 BST 2008
I'm using shared hosting for several Cat deployments. This means I
can't do nice Location/Apache tricks or lighttpd or modperl. I am
running fastcgi but I have to deploy it with nothing but mod_rewrite
at my disposal.
Essentially this is just so that
- /deploy_dir/myapp.fcgi/cat/path/args
Can always look like
- /deploy_dir/cat/path/args
And uri_for will correctly drop the script name. It might seem silly
but it's important so the URI structure will not change if deployment
changes. I don't like having several versions of the same little hook
to make it work the way I want so I'm going to do a plugin. I'm asking-
- What should this be named? Catalyst::Plugin::IhaveNoFreakingIdea...
- Is the following code and the .htaccess info entirely correct? It
will serve as the POD examples. What could be better?
I've been using this code in production for a year and a half without
trouble but that doesn't mean it's right (especially the mod_rewrite
stuff). So I *really* appreciate any help bomb-proofing it.
# I think this config stuff can't be done this way in a plugin;
# have to do a merge or something that I'll have to look up.
use File::Spec;
__PACKAGE__->config->{application_executable} = (File::Spec-
>splitpath($0))[-1];
sub uri_for {
my $self = shift;
my $uri = $self->NEXT::uri_for(@_);
my $program_name = $self->config->{application_executable};
$uri =~ s,/\Q$program_name\E(?=/|\z),,;
return ref($uri) ? $uri : URI->new($uri);
}
.htaccess # This one implies a / deployment.
-----------------------
DirectoryIndex myapp.fcgi index.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !myapp.fcgi$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*[^/])$
RewriteRule ^(.*)/$ /$1 [QSA,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /myapp.fcgi/$1 [QSA,L]
Thanks for looking!
-Ashley
--
More information about the Catalyst
mailing list