You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Will Fould <wi...@gmail.com> on 2006/10/26 03:48:38 UTC

Transhandler? Redirect permanent?

(MP2-Apache2)

I have a fast growing number of virtual (non-existant) subdirectories under
document root:

   /apple
   /foo
   /grape
   /bar

each one corresponds to a dynamic document.

Until now, I've just used:

   Redirect permanent /apple
http://www.example.com/content.cgi?content=apple
 .... foo
   Redirect permanent /grape
http://www.example.com/content.cgi?content=grape
 .... bar


But I *really* need to start checking a database for the content and handle
the redirect dynamically... (the content list is getting very long!).

Since this check happens at the document root, some directories exist as
well as some files, index.html, etc.

I've started testing a handler (configured at '/') that parses $r->uri and
checks the object, doing a redirect accordingly, but this seems wasteful for
every hit.
I've thought about using the handler for only 404...

How can this most effeciently be handled using the virtual name?


Thanks in advance?

Re: Transhandler? Redirect permanent?

Posted by Tyler MacDonald <ty...@yi.org>.
Will Fould <wi...@gmail.com> wrote:
> I've started testing a handler (configured at '/') that parses $r->uri and
> checks the object, doing a redirect accordingly, but this seems wasteful for
> every hit.
> I've thought about using the handler for only 404...
> 
> How can this most effeciently be handled using the virtual name?

	mod_perl is great if you want to make complex decisions to arrive at
the dynamic document in question, but if you just want to provide mappings
based on a simple key/value table, I strongly suggest you use mod_rewrite.
Here's a good starting point for that:

	http://httpd.apache.org/docs/2.2/rewrite/

	The advantage is that in most cases, you end up with 2 or 3 lines of
code inline in your httpd.conf to handle the problem, instead of the
mod_perl way of writing a separate .pm with a handler whose overhead is
going to be at least 10 lines before you even start coding.

	I use both extensively and together; mod_perl for the content,
authentication, etc... and mod_rewrite for traffic control.

	Cheers,
		Tyler


Re: Transhandler? Redirect permanent?

Posted by Jonathan <mo...@2xlp.com>.
On Oct 25, 2006, at 9:48 PM, Will Fould wrote:

> I've started testing a handler (configured at '/') that parses $r- 
> >uri and checks the object, doing a redirect accordingly, but this  
> seems wasteful for every hit.
> I've thought about using the handler for only 404...
>

Personally, i use a dispatch table and dispatch regex system --  
sample organization code below

i see if a stripped uri is in the dispatch, if its not i loop/recurse  
regex trees looking for  matches/better matches

if i get nothing, then i go 404

the static and regex lookups are negligible.   i think they're like  
1/50000 seconds, or soemthing ridiculously fast like that on my  
slowest box

========

use constant URL_Dispatch=> {
	'/'=> 'FindMeOn::Syndicate::Base::Default',
	'_default'=> 'FindMeOn::Syndicate::Base::Default',
	'/findmeon/visit/'=> 'FindMeOn::Syndicate::Base::Findmeon::Visit',
};

use constant URL_RegexDispatch=> [
	{
		regex=> qr/^\/findmeon\//,
		sections=> [
			# findmeon-embeds , links
			{
				'regex' 	=> qr/^\/findmeon\/findmeons\/([\w]{32})\/v1(:?\/)?$/,
				'package' 	=> 'FindMeOn::Syndicate::Base::Findmeon::Findmeons::v1',
				'id_fields'=> ['hex_id']
			},
	}
];

// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -