You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Robert Chou <ro...@rcreations.com> on 2001/04/30 05:36:45 UTC

how I got mod_rewrite working while converting from Apache+JServ

After reading Mike Bremford's workaround and spending a little
more time troubleshooting, I've found a workaround which works
with the ApJServAction and rewrite directives. Here's a summary
note and a patch.

rob

---

Here's what I noticed while trying to convert from JServ
to Tomcat using Apache. I had many "ApJServAction" directives
which mapped some file extensions to a servlet
(ie. "ApJServAction .tsp /servlet/gnutsp").
Also, I had some rewrite directives to which stripped url embedded
information (ie. "RewriteRule ^(.*,[0123]t,.*)\.html$ $1.tsp").
I got these to work by replacing the requestURI with the
rewritten URI.
Initially, the rewritten uri is store in pathInfo.
The original uri is stored in requestURI.
The mapped servlet (from ApJServAction) is stored in "script name".
If the requestURI value is replaced, it's backed up in the
attribute "org.apache.mod_rewrite.originalURI".
As a side note, if you use ApJServAction, make sure the
Initially, the rewritten uri is store in pathInfo.

---

*** Ajp12ConnectionHandler.java.orig	Thu Sep 14 11:52:14 2000
--- Ajp12ConnectionHandler.java	Thu Sep 14 14:46:53 2000
***************
*** 296,303 ****
  		    dummy =3D ajpin.readString(null);                   //script = 
filename
  		    //		System.out.println("AJP: Script filen=" + dummy);

  		    dummy = ajpin.readString(null);                   //script name
! 		    //		System.out.println("AJP: Script name=" + dummy);

  		    serverName = ajpin.readString("");                //server name
  		    if( doLog ) log("AJP: serverName=" + serverName );
--- 296,321 ----
  		    dummy = ajpin.readString(null);                   //script = filename
  		    //		System.out.println("AJP: Script filen=" + dummy);
  		    
+ 		    // When using mod_rewrite from Apache 1.3.x, the rewritten URI
+ 		    // is passed in as the script name. In CGI scripts and = Apache/JServ,
+ 		    // the request URI is left as is, and the script name (in CGI) = or 
the
+ 		    // servlet path (in Apache/JServ) is set to the rewritten = version.
+ 		    //
+ 		    // We can't do this becuase it violates newer versions of the = 
Servlet
+ 		    // spec (2.2 up). So we compromise. The rewritten URI becomes the
+ 		    // actual URI, and the original URI is stored as an attribute.
+ 		    //
+ 		    // XXX I don't know what effect this will have with other = 
webservers.
+ 		    // In the unlikely event that they pass non-null garbage in this = 
field,
+ 		    // I guess we'll get a garbage URI. Maybe a parameter could be = set 
on 
+ 		    // the Connector to switch this check on and off?
+ 		    //
  		    dummy = ajpin.readString(null);                   //script name
! 		    if (!"".equals(dummy) && !requestURI.equals(dummy)) {
! 		    	setAttribute("org.apache.mod_rewrite.originalURI", requestURI);
! 		    	if( doLog ) log("AJP: URI rewritten from "+requestURI+" to = 
"+dummy);
! 		    	requestURI = dummy;
! 		    }

  		    serverName = ajpin.readString("");                //server name
  		    if( doLog ) log("AJP: serverName=" + serverName );