[Catalyst-dev] RT #24132: [WISH] redirect if missing trailing / from Catalyst root

Brian Cassidy brian.cassidy at nald.ca
Wed May 28 13:46:43 GMT 2008


On behalf of "CDOLAN <cpan at chrisdolan.net> ":

CDOLAN <cpan at chrisdolan.net>

I'm running a Catalyst app at a non-server-root location, say
http://example.com/foo/. When accessing the app root properly with the
trailing slash, Catalyst correctly processes path '/'. However, when
requesting the URL without the slash (like http://example.com/foo)
Catalyst processes path '/foo' instead of '/'.

This is a common problem that can be solved via Apache redirect, but it
would be convenient if Catalyst could solve it by itself. I propose the
following trivial fix, but am unsure where it belongs in the code base:

if ($c->req->uri . '/' eq $c->req->base) {
$c->req->redirect($c->req->base);
return;
}

Perhaps this could even be a plugin that runs at the prepare_path phase?

An incorrect solution would be to internally pretend the URL had the
slash because that would break relative URLs (but you already knew that...).

--

The original RT ticket can be found here:

http://rt.cpan.org/Ticket/Display.html?id=24132



More information about the Catalyst-dev mailing list