You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Brendan Benke <be...@impulseradio.com> on 2002/08/07 16:46:14 UTC

Here we go again - mod_webapp and mod_rewrite

i originally posted this to tomcat-users, but i think it might be better
served here.

i know this topic is old and has been discussed at length before, i'm still
having trouble finding an elegant solution.  i used to use apache with
mod_jserv and some simple url rewriting.   moving to tomcat, i have
encountered problems with mod_webapp and mod_rewrite.  specifically, the
original URI being rewritten instead of just passed through.

for example:  (these are nested inside VirtualHost tags)

==================
    ApJServMount /servlets ajpv12://localhost:8007/root

<IfModule mod_rewrite.c>
       RewriteEngine on
       RewriteCond %{REQUEST_URI} !^/ir/images
       RewriteCond %{REQUEST_URI} !^/ir/html
       RewriteCond %{REQUEST_URI} !^/ir/applets
       RewriteCond %{REQUEST_URI} !^/ir/dtds
       RewriteCond %{REQUEST_URI} !^/index.html
       RewriteRule ^/.*  /servlets/RequestHandler [PT]
</IfModule>

==================

used to work with ApacheJServ and  ApacheModuleRewrite.dll while

==================
 WebAppConnection warpConnection warp localhost:8008

<IfModule mod_rewrite.c>
       RewriteEngine on
       RewriteCond %{REQUEST_URI} !^/ir/images
       RewriteCond %{REQUEST_URI} !^/ir/html
       RewriteCond %{REQUEST_URI} !^/ir/applets
       RewriteCond %{REQUEST_URI} !^/ir/dtds
       RewriteCond %{REQUEST_URI} !^/index.html
       RewriteRule ^/.*  /site/servlet/RequestHandler [PT]
</IfModule>

  WebAppDeploy site warpConnection /site
==================
doesn't work at all.  using the [R] flag does sucessfully redirect the
rewritten request, but the new URI is used instead of the old, as was the
behavior under JServ.

can anyone point me in the right direction here?  i've seen home-brew
patches to various connection handlers that see to fudge the behavior i'm
looking for, but certainly there must be something i'm missing.

i'm using:
tomcat 4.0.4
apache 1.3.26
windows 2000

any help much appreciated!!!!

brendan



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Here we go again - mod_webapp and mod_rewrite

Posted by Dan Lindy <da...@touchmove.com>.
Brendan,

I had a similar experience back in April and solved it by hacking 
mod_webapp myself. I tried posting my problem to tomcat-dev only to be 
greeted with credulity as Tomcat takes the high road with respect to being 
a reference implementation and mod_rewrite lets you do things Sun's 
specification specifically prohibits. None-the-less, I am true believer in 
mod_rewrite and was un-willing to give it up, especially because there are 
things you just can't do without it.

Below is a listing of my hack to mod_webapp.c. It works fine on RH Linux 
6.2 and 7.2, but I have not tried it on Windows, so you're on your own as 
far as compiling it.

Hope this helps,
Dan


         /* Match an Apache request */
         static int wam_match(request_rec *r) {
             wa_virtualhost *host=NULL;
         //    wa_application *appl=NULL;
         //    wa_chain *elem=NULL;

             /* Paranoid check */
             if (!wam_initialized) return(DECLINED);

             /* Check if this host was recognized */
             host=ap_get_module_config(r->server->module_config,&webapp_module);
             if (host==NULL) return(DECLINED);

         //    /* Check if the uri is contained in one of our applications 
root path */
         //    elem=host->apps;
         //    while(elem!=NULL) {
         //        appl=(wa_application *)elem->curr;
         //        if (strncmp(appl->rpth,r->uri,strlen(appl->rpth))==0) break;
         //
         //        appl=NULL;
         //        elem=elem->next;
         //    }
         //    if (appl==NULL) return(DECLINED);

             /* The uri path is matched: set the handler and return */
             r->handler=ap_pstrdup(r->pool,"webapp-handler");

         //    /* Set the webapp request structure into Apache's request 
structure */
         //    ap_set_module_config(r->request_config, &webapp_module, appl);
         //    return(OK);
             return(DECLINED);  // added

         }

         /* Handle the current request */
         static int wam_invoke(request_rec *r) {
             server_rec *svr=r->server;
             conn_rec *con=r->connection;
             wa_virtualhost *host=NULL;   // added
             wa_application *appl=NULL;
             wa_chain *elem=NULL;         // added
             wa_request *req=NULL;
             const char *msg=NULL;
             char *stmp=NULL;
             char *ctmp=NULL;
             char *ssl_temp;
             int ret=0;

             /* Paranoid check */
             if (!wam_initialized) return(DECLINED);

         // begin added...

             /* Check if this host was recognized */
             host=ap_get_module_config(r->server->module_config,&webapp_module);
             if (host==NULL) return(DECLINED);

             /* Check if the uri is contained in one of our applications 
root path */
             elem=host->apps;
             while(elem!=NULL) {
                 appl=(wa_application *)elem->curr;
                 if (strncmp(appl->rpth,r->uri,strlen(appl->rpth))==0) break;

                 appl=NULL;
                 elem=elem->next;
             }
             if (appl==NULL) return(DECLINED);

             /* Set the webapp request structure into Apache's request 
structure */
             ap_set_module_config(r->request_config, &webapp_module, appl);

         // ...end added



At 10:46 AM 8/7/02 -0400, Brendan Benke wrote:
>i originally posted this to tomcat-users, but i think it might be better
>served here.
>
>i know this topic is old and has been discussed at length before, i'm still
>having trouble finding an elegant solution.  i used to use apache with
>mod_jserv and some simple url rewriting.   moving to tomcat, i have
>encountered problems with mod_webapp and mod_rewrite.  specifically, the
>original URI being rewritten instead of just passed through.
>
>for example:  (these are nested inside VirtualHost tags)
>
>==================
>     ApJServMount /servlets ajpv12://localhost:8007/root
>
><IfModule mod_rewrite.c>
>        RewriteEngine on
>        RewriteCond %{REQUEST_URI} !^/ir/images
>        RewriteCond %{REQUEST_URI} !^/ir/html
>        RewriteCond %{REQUEST_URI} !^/ir/applets
>        RewriteCond %{REQUEST_URI} !^/ir/dtds
>        RewriteCond %{REQUEST_URI} !^/index.html
>        RewriteRule ^/.*  /servlets/RequestHandler [PT]
></IfModule>
>
>==================
>
>used to work with ApacheJServ and  ApacheModuleRewrite.dll while
>
>==================
>  WebAppConnection warpConnection warp localhost:8008
>
><IfModule mod_rewrite.c>
>        RewriteEngine on
>        RewriteCond %{REQUEST_URI} !^/ir/images
>        RewriteCond %{REQUEST_URI} !^/ir/html
>        RewriteCond %{REQUEST_URI} !^/ir/applets
>        RewriteCond %{REQUEST_URI} !^/ir/dtds
>        RewriteCond %{REQUEST_URI} !^/index.html
>        RewriteRule ^/.*  /site/servlet/RequestHandler [PT]
></IfModule>
>
>   WebAppDeploy site warpConnection /site
>==================
>doesn't work at all.  using the [R] flag does sucessfully redirect the
>rewritten request, but the new URI is used instead of the old, as was the
>behavior under JServ.
>
>can anyone point me in the right direction here?  i've seen home-brew
>patches to various connection handlers that see to fudge the behavior i'm
>looking for, but certainly there must be something i'm missing.
>
>i'm using:
>tomcat 4.0.4
>apache 1.3.26
>windows 2000
>
>any help much appreciated!!!!
>
>brendan
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Here we go again - mod_webapp and mod_rewrite

Posted by Pier Fumagalli <pi...@betaversion.org>.
"Brendan Benke" <be...@impulseradio.com> wrote:

> touche!  so let me ask you this, what are some alternative connectors?
> mod_webapp seems like the most current and best idea.

We're woring on mod_webapp for Apache 2.0, and that will work with windows
as well, now that Aaron wrote the APR resourcelist, we're really close to
completion.

    Pier


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Here we go again - mod_webapp and mod_rewrite

Posted by Brendan Benke <be...@impulseradio.com>.
touche!  so let me ask you this, what are some alternative connectors?
mod_webapp seems like the most current and best idea.


----- Original Message -----
From: "Pier Fumagalli" <pi...@betaversion.org>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
Sent: Wednesday, August 07, 2002 10:54 AM
Subject: Re: Here we go again - mod_webapp and mod_rewrite


> "Brendan Benke" <be...@impulseradio.com> wrote:
>
> > i'm using:
> > tomcat 4.0.4
> > apache 1.3.26
> > windows 2000
>
>
http://cvs.apache.org/viewcvs.cgi/*checkout*/jakarta-tomcat-connectors/webap
> p/README.txt?rev=1.18
>
> Read the first few lines.
>
>     Pier
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Here we go again - mod_webapp and mod_rewrite

Posted by Pier Fumagalli <pi...@betaversion.org>.
"Brendan Benke" <be...@impulseradio.com> wrote:

> i'm using:
> tomcat 4.0.4
> apache 1.3.26
> windows 2000

http://cvs.apache.org/viewcvs.cgi/*checkout*/jakarta-tomcat-connectors/webap
p/README.txt?rev=1.18

Read the first few lines.

    Pier


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Here we go again - mod_webapp and mod_rewrite

Posted by Dan Lindy <da...@touchmove.com>.
Brendan,

I had a similar experience back in April and solved it by hacking 
mod_webapp myself. I tried posting my problem to tomcat-dev only to be 
greeted with credulity as Tomcat takes the high road with respect to being 
a reference implementation and mod_rewrite lets you do things Sun's 
specification specifically prohibits. None-the-less, I am true believer in 
mod_rewrite and was un-willing to give it up, especially because there are 
things you just can't do without it.

Below is a listing of my hack to mod_webapp.c. It works fine on RH Linux 
6.2 and 7.2, but I have not tried it on Windows, so you're on your own as 
far as compiling it.

Hope this helps,
Dan


         /* Match an Apache request */
         static int wam_match(request_rec *r) {
             wa_virtualhost *host=NULL;
         //    wa_application *appl=NULL;
         //    wa_chain *elem=NULL;

             /* Paranoid check */
             if (!wam_initialized) return(DECLINED);

             /* Check if this host was recognized */
             host=ap_get_module_config(r->server->module_config,&webapp_module);
             if (host==NULL) return(DECLINED);

         //    /* Check if the uri is contained in one of our applications 
root path */
         //    elem=host->apps;
         //    while(elem!=NULL) {
         //        appl=(wa_application *)elem->curr;
         //        if (strncmp(appl->rpth,r->uri,strlen(appl->rpth))==0) break;
         //
         //        appl=NULL;
         //        elem=elem->next;
         //    }
         //    if (appl==NULL) return(DECLINED);

             /* The uri path is matched: set the handler and return */
             r->handler=ap_pstrdup(r->pool,"webapp-handler");

         //    /* Set the webapp request structure into Apache's request 
structure */
         //    ap_set_module_config(r->request_config, &webapp_module, appl);
         //    return(OK);
             return(DECLINED);  // added

         }

         /* Handle the current request */
         static int wam_invoke(request_rec *r) {
             server_rec *svr=r->server;
             conn_rec *con=r->connection;
             wa_virtualhost *host=NULL;   // added
             wa_application *appl=NULL;
             wa_chain *elem=NULL;         // added
             wa_request *req=NULL;
             const char *msg=NULL;
             char *stmp=NULL;
             char *ctmp=NULL;
             char *ssl_temp;
             int ret=0;

             /* Paranoid check */
             if (!wam_initialized) return(DECLINED);

         // begin added...

             /* Check if this host was recognized */
             host=ap_get_module_config(r->server->module_config,&webapp_module);
             if (host==NULL) return(DECLINED);

             /* Check if the uri is contained in one of our applications 
root path */
             elem=host->apps;
             while(elem!=NULL) {
                 appl=(wa_application *)elem->curr;
                 if (strncmp(appl->rpth,r->uri,strlen(appl->rpth))==0) break;

                 appl=NULL;
                 elem=elem->next;
             }
             if (appl==NULL) return(DECLINED);

             /* Set the webapp request structure into Apache's request 
structure */
             ap_set_module_config(r->request_config, &webapp_module, appl);

         // ...end added



At 10:46 AM 8/7/02 -0400, Brendan Benke wrote:
>i originally posted this to tomcat-users, but i think it might be better
>served here.
>
>i know this topic is old and has been discussed at length before, i'm still
>having trouble finding an elegant solution.  i used to use apache with
>mod_jserv and some simple url rewriting.   moving to tomcat, i have
>encountered problems with mod_webapp and mod_rewrite.  specifically, the
>original URI being rewritten instead of just passed through.
>
>for example:  (these are nested inside VirtualHost tags)
>
>==================
>     ApJServMount /servlets ajpv12://localhost:8007/root
>
><IfModule mod_rewrite.c>
>        RewriteEngine on
>        RewriteCond %{REQUEST_URI} !^/ir/images
>        RewriteCond %{REQUEST_URI} !^/ir/html
>        RewriteCond %{REQUEST_URI} !^/ir/applets
>        RewriteCond %{REQUEST_URI} !^/ir/dtds
>        RewriteCond %{REQUEST_URI} !^/index.html
>        RewriteRule ^/.*  /servlets/RequestHandler [PT]
></IfModule>
>
>==================
>
>used to work with ApacheJServ and  ApacheModuleRewrite.dll while
>
>==================
>  WebAppConnection warpConnection warp localhost:8008
>
><IfModule mod_rewrite.c>
>        RewriteEngine on
>        RewriteCond %{REQUEST_URI} !^/ir/images
>        RewriteCond %{REQUEST_URI} !^/ir/html
>        RewriteCond %{REQUEST_URI} !^/ir/applets
>        RewriteCond %{REQUEST_URI} !^/ir/dtds
>        RewriteCond %{REQUEST_URI} !^/index.html
>        RewriteRule ^/.*  /site/servlet/RequestHandler [PT]
></IfModule>
>
>   WebAppDeploy site warpConnection /site
>==================
>doesn't work at all.  using the [R] flag does sucessfully redirect the
>rewritten request, but the new URI is used instead of the old, as was the
>behavior under JServ.
>
>can anyone point me in the right direction here?  i've seen home-brew
>patches to various connection handlers that see to fudge the behavior i'm
>looking for, but certainly there must be something i'm missing.
>
>i'm using:
>tomcat 4.0.4
>apache 1.3.26
>windows 2000
>
>any help much appreciated!!!!
>
>brendan
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>