[Catalyst] RFC for plugin to strip script name from URI;
plugin name + code review
Matt S Trout
dbix-class at trout.me.uk
Sun Apr 6 20:44:57 BST 2008
On Sat, Mar 29, 2008 at 11:27:39PM -0700, Ashley wrote:
> 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]
Isn't it possible in mod_rewrite to use the P flag to pass the original
URI through so it things it was at / in the first place?
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the Catalyst
mailing list