[Catalyst] "rewrite mode" option for CGI engine

Keith Grennan keith at squeegeemedia.com
Tue Apr 26 11:52:03 CEST 2005


Hey,

One thing that would be nice to have in the Catalyst::Engine::CGI is to
optionally prefer $ENV{REQUEST_URI} to $ENV{PATH_INFO} when setting $c->path.

With mod_rewrite, it would let you have URLs like foo.com/ping instead of
foo.com/index.cgi/ping.

I use an htaccess setup like this:

Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex index.cgi
RewriteEngine On
# Next two lines allow requests for real 
# files to still go through the webserver
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# All other requests go to index.cgi
RewriteRule ^(.*) index.cgi [L,QSA]

Here is the changed Catalyst::Engine::CGI:

--- CGI.pm.orig Tue Apr 26 02:35:42 2005
+++ CGI.pm      Tue Apr 26 02:36:59 2005
@@ -175,7 +175,7 @@
         $base = $base->canonical->as_string;
     }
 
-    my $path = $ENV{PATH_INFO} || '/';
+    my $path = ($c->config->{engine}{rewrite_mode} ? $ENV{REQUEST_URI} : $ENV{PATH_INFO}) || '/';
     $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
     $path =~ s/^\///;
 
Cheers,
Keith



More information about the Catalyst mailing list