Search code examples
apacheapache2mod-perl

Apache mod_perl handler/dispatcher returning control to apache


Is it possible to have an apache mod_perl handler, which receives all incoming requests and decides based upon a set of rules if this request is something it wants to act upon, and if not, return control to apache which would serve the request as normal?

A use-case:

A legacy site which uses DirectoryIndex for serving index.html (or similar) and default handlers for perl scripts etc, is being given a freshened up url-scheme (django/catalyst-ish). A dispatcher will have a set of urls mapped to controllers that are dispatched based on the incoming url.

However, the tricky part is having this dispatcher within the same namespace on the same vhost as the old site. The thought is to rewrite the site piece by piece, as a "update all" migration gives no chance in testing site performance with the new system, nor is it feasible due to the sheer size of the site.

One of the many problems, is that the dispatcher now receives all URLs as expected, but DirectoryIndex and static content (which is mostly served by a different host, but not everything) is not served properly. The dispatcher returns an Apache::Const::DECLINED for non-matching urls, but Apache does not continue to serve the request as it normally would, but instead gives the default error page. Apache does not seem to try to look for /index.html etc.

How can this be solved? Do you need to use internal redirects? Change the handler stack in the dispatcher? Use some clever directives? All of the above? Not possible at all?

All suggestions are welcome!


Solution

  • I have done a similar thing but a while back, so I might be a little vague:

    • I think you need to have the standard file handler (I believe this is done using the set-handler directive) as well as the perl handler in the stack
    • You might need to use PerlTransHandler or a similar one to hook into the filename/url mapping phase and make sure the next handler inline will pick the right file up off the filesystem.