Re: rewriterule, location, and perlhandler

2009-07-22 Thread Eric Lease Morgan


On Jul 22, 2009, at 10:27 AM, Torsten Foertsch wrote:

If you want, it's actually possible to take this even further and  
remove rewrite completely.


Location /etexts/id/
  SetHandler perl-script
  PerlHandler Apache2::Alex::SemanticWeb
/Location

Then alter your handler's code to parse $r-uri and extract
everything after $r-location. (or you can use $r-path_info, if the
/etexts/id/ actually exists in your document root).  That'll give you
the same thing that rewrite is currently stuffing into your id
argument.


Never use path_info unless you are very sure it is what you want.
Path_info is made for CGI scripts where $r-filename points to the  
file

containing the script

substr($r-uri, length $r-location) is almost always what you need.



These two things represent a very elegant solution that I have already  
implemented. Cool. Thanks!


--
Eric Lease Morgan



rewriterule, location, and perlhandler

2009-07-21 Thread Eric Lease Morgan


How do I get Apache's RewriteRule, Location, and PerlHander to work  
nicely together?


I have a the following Hello World mod_perl module:

  package Apache2::Alex::SemanticWeb;

  use Apache2::Const -compile = qw( OK );
  use strict;

  sub handler {

my $r = shift;
$r-content_type( 'text/html' );
$r-print( 'hello, world!' );
return Apache2::Const::OK;

  }

  1;

I then touch a file named semantic-web.cgi.

I then add a Location directive to httpd.conf:

  Location /sandbox/semantic-web.cgi
SetHandler perl-script
PerlHandler Apache2::Alex::SemanticWeb
  /Location

I then use my browser to go to the following URL, and it returns  
hello, world!:


  http://infomotions.com/sandbox/semantic-web.cgi

Great and wonderful.

I now want to implement a RewriteRule -- a la a cool linked data URL  
-- to redirect URLs with a specific shape to SemanticWeb.pm, and I use  
the following:


  RewriteRule ^/etexts/id/(.*) /sandbox/semantic-web.cgi?id=$1

In other words, all request starting with /etexts/id should be  
redirected (rewritten) to go to semantic-web.cgi. Unfortunately, all  
requests go directly to the touched file and not to my Perl package;  
the Location directive seems by-passed. When I remove semantic-web.cgi  
from my file system I get a 404 error (file not found).


What am I doing wrong? Does an actual file need to exist in order for  
mod_perl to find it? How should I edit httpd.conf so I can: 1) rewrite  
GET requests, and 2) execute the result in a mod_perl module?


--
Eric Lease Morgan
Infomotions, Inc.




Re: rewriterule, location, and perlhandler

2009-07-21 Thread Eric Lease Morgan


On Jul 21, 2009, at 9:45 PM, Nick Wellnhofer wrote:


What am I doing wrong? Does an actual file need to exist in order for
mod_perl to find it?


No.



I didn't think so, but what sort of configuration do I need to do so  
my mod_perl packages get executed without the existence of a file?


--
Eric Morgan