You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by amduser amduser <am...@yahoo.com> on 2001/08/20 21:50:20 UTC

Q: How to use mod_rewrite with mod_jk?

Q: How to use mod_rewrite with mod_jk?

I am trying to get mod_rewrite to work with mod_jk,
but am not having any luck. I've tried placing the
AddModule line for mod_jk both before and after the
AddModule line for mod_rewrite. Using the PT flag on
rewrite rules doesn't help either. The same rewrite
rules work perfectly with Caucho Resin's mod_caucho.
It seems as though Tomcat is passed only the original
URL and not the rewritten URL. I have searched the
archives and the net but have found nothing that
solves this problem.

Windows: tomcat 3.2.3; mod_jk.dll 2001-07-17; apache
1.3.20; sun jdk 1.3.0; windows 2000 sp2
Linux: tomcat 3.2.3; mod_jk-noeapi.so 2001-07-20;
apache 1.3.20; ibm jdk 1.3.0; linux 2.2.13


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: Q: How to use mod_rewrite with mod_jk?

Posted by amduser amduser <am...@yahoo.com>.
--- Denis Haskin <De...@HaskinFerguson.net> wrote:
>...
> I wonder if it's a bug just with directory listing?  Can you get to 
> servlets or JSP pages via the rewrite rule?
>
> What happens when you do the rewritten url with a trailing slash
> (e.g.  http://localhost/rewrite/examples/)?  

That doesn't work either, it's the same problem: Tomcat sees only the
original URL, not the rewritten URL.

I even tried commenting out the AddModule lines for all but the
absolute minimum required Apache modules: mod_so, mod_alias, mod_jk,
and mod_rewrite. Incidentally, I discovered that mod_jk must be loaded
after mod_alias, otherwise URLs are not passed to mod_jk and instead
one sees the source code for the JSP files.

> Apologies that I couldn't be more help...

Thanks for your help anyway. I will try posting to the developer list.


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: Q: How to use mod_rewrite with mod_jk?

Posted by Denis Haskin <De...@HaskinFerguson.net>.
It does appear that you have everything set up properly.

I'm unable to duplicate the behavior you're seeing, but the environment 
I have to test it is Solaris, Apache 1.3.19, Tomcat 3.2.1.

I wonder if it's a bug just with directory listing?  Can you get to 
servlets or JSP pages via the rewrite rule?

What happens when you do the rewritten url with a trailing slash (e.g. 
http://localhost/rewrite/examples/)?  There's been some discussion in 
the mailing list about handling of trailing slashes, and I seem to 
recall there's some issues with that.

Apologies that I couldn't be more help...

dwh


amduser amduser wrote:

>[...]
>
>The rewrite log says
>
>][rid#8650b0/initial] (3) applying pattern '^/rewrite/examples(.*)' to
>uri '/rewrite/examples'
>127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
>[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) rewrite /rewrite/examples
>-> /webapps/examples
>127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
>[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) forcing
>'/webapps/examples' to get passed through to next API URI-to-filename
>handler
>
>* Response to http://localhost/webapps/examples:
>
>	... correct directory listing ...
>
>* Response to http://localhost/rewrite/examples:
>
>	Not Found (404)
>	Original request: /rewrite/examples
>	Not found request: /rewrite/examples 
>	
>[...etc...]
>



Re: Q: How to use mod_rewrite with mod_jk?

Posted by amduser amduser <am...@yahoo.com>.
--- Denis Haskin <De...@HaskinFerguson.net> wrote:
>... I guess I would recommend turning mod_rewrite logging up to 
> full and make sure that the final rewritten URL from mod_rewrite is
> what you expect it to be.

The rewritten URL looks good to me.

> Actually, now that I read your message more closely, I'm not sure I 
> understand the problem.  It sounds like the requests *are* getting to
> 
> Tomcat but they aren't in the form you expect when they get there? 
> Or 
> are the requests not getting to Tomcat at all?

Tomcat sees only the original request, not the rewritten URL.

> Perhaps some examples and some RewriteRule snippets would help.

Here's everything I could think of. The RewriteRule for this test is

RewriteRule ^/rewrite/examples(.*) /webapps/examples$1 [PT]

The rewrite log says

][rid#8650b0/initial] (3) applying pattern '^/rewrite/examples(.*)' to
uri '/rewrite/examples'
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) rewrite /rewrite/examples
-> /webapps/examples
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) forcing
'/webapps/examples' to get passed through to next API URI-to-filename
handler

* Response to http://localhost/webapps/examples:

	... correct directory listing ...

* Response to http://localhost/rewrite/examples:

	Not Found (404)
	Original request: /rewrite/examples
	Not found request: /rewrite/examples 
	
* Additions to default httpd.conf:

LoadModule jk_module modules/mod_jk.dll
LoadModule rewrite_module modules/mod_rewrite.so
ClearModuleList
AddModule mod_so.c mod_mime.c mod_access.c mod_auth.c mod_negotiation.c
AddModule mod_include.c mod_autoindex.c mod_dir.c mod_cgi.c
mod_userdir.c
AddModule mod_alias.c mod_env.c mod_log_config.c mod_asis.c mod_imap.c
AddModule mod_actions.c mod_setenvif.c mod_isapi.c
AddModule mod_jk.c
AddModule mod_rewrite.c

# Tomcat
<IfModule mod_jk.c>
	JkWorkersFile d:/tomcat.prp
	JkLogFile d:/apache1.3.20/logs/mod_jk.log
	JkLogLevel debug
	JkMount /*.jsp ajp12
	JkMount /webapps/* ajp12
</IfModule>

# Rewrite rules
<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteOptions inherit
	RewriteLogLevel 9
	RewriteLog d:/apache1.3.20/logs/rewrite.log
	RewriteRule ^/rewrite/examples(.*) /webapps/examples$1 [PT]
</IfModule>

* Changes to tomcat's default server.xml: changed context path
for /examples and /admin to /webapps/examples and /webapps/admin,
respectively.

* Tomcat properties file (tomcat.prp):

worker.list=ajp12, ajp13

worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
worker.ajp12.lbfactor=1

worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

* Tomcat console output:

Starting tomcat. Check logs/tomcat.log for error messages
2001-08-21 00:04:47 - ContextManager: Adding context Ctx(
/webapps/examples )
2001-08-21 00:04:47 - ContextManager: Adding context Ctx(
/webapps/admin )
2001-08-21 00:04:47 - ContextManager: Adding context Ctx( /admin )
2001-08-21 00:04:47 - ContextManager: Adding context Ctx( /examples )
2001-08-21 00:04:47 - ContextManager: Adding context Ctx(  )
2001-08-21 00:04:47 - ContextManager: Adding context Ctx( /test )
2001-08-21 00:04:48 - PoolTcpConnector: Starting HttpConnectionHandler
on 8080
2001-08-21 00:04:48 - PoolTcpConnector: Starting Ajp12ConnectionHandler
on 8007
2001-08-21 00:05:25 - Ctx(  ): 404 R(  + /rewrite/examples + null) null

* Log files

$ cat access.log
127.0.0.1 - - [21/Aug/2001:00:05:17 -0400] "GET /webapps/examples
HTTP/1.1" 200 1406
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400] "GET /rewrite/examples
HTTP/1.1" 404 181

$ cat error.log
(empty)

$ cat rewrite.log
127.0.0.1 - - [21/Aug/2001:00:05:17 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) init rewrite engine with
requested uri /webapps/examples
127.0.0.1 - - [21/Aug/2001:00:05:17 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (3) applying pattern
'^/rewrite/examples(.*)' to uri '/webapps/examples'
127.0.0.1 - - [21/Aug/2001:00:05:17 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (1) pass through
/webapps/examples
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) init rewrite engine with
requested uri /rewrite/examples
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (3) applying pattern
'^/rewrite/examples(.*)' to uri '/rewrite/examples'
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) rewrite /rewrite/examples
-> /webapps/examples
127.0.0.1 - - [21/Aug/2001:00:05:25 -0400]
[foo.lan/sid#7a60f0][rid#8650b0/initial] (2) forcing
'/webapps/examples' to get passed through to next API URI-to-filename
handler

$ cat mod_jk.log
(lots of fairly uninformative stuff)

$ cat servlet.log
2001-08-21 00:04:47 - path="/webapps/examples" :jsp: init
2001-08-21 00:04:47 - path="/webapps/admin" :jsp: init
2001-08-21 00:04:47 - path="/admin" :jsp: init
2001-08-21 00:04:47 - path="/examples" :jsp: init
2001-08-21 00:04:48 - path="" :jsp: init
2001-08-21 00:04:48 - path="/test" :jsp: init

$ cat jasper.log
2001-08-21 00:04:47 - Scratch dir for the JSP engine is:
d:\tomcat3.2.3\work\localhost_8080%2Fwebapps%2Fexamples
2001-08-21 00:04:47 - IMPORTANT: Do not modify the generated servlets



__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: Q: How to use mod_rewrite with mod_jk?

Posted by Denis Haskin <De...@HaskinFerguson.net>.
Hmm. Works fine for us (Tomcat 3.2.x, Apache 1.3.19, Solaris, jdk 1.3.1).

Given that you're tried the ordering of the AddModule lines (don't know 
if LoadModule needs to be in order too--wouldn't think so) and you have 
the PT flag, I guess I would recommend turning mod_rewrite logging up to 
full and make sure that the final rewritten URL from mod_rewrite is what 
you expect it to be.

Actually, now that I read your message more closely, I'm not sure I 
understand the problem.  It sounds like the requests *are* getting to 
Tomcat but they aren't in the form you expect when they get there?  Or 
are the requests not getting to Tomcat at all?

Perhaps some examples and some RewriteRule snippets would help.

dwh


amduser amduser wrote:

>Q: How to use mod_rewrite with mod_jk?
>
>I am trying to get mod_rewrite to work with mod_jk,
>but am not having any luck. I've tried placing the
>AddModule line for mod_jk both before and after the
>AddModule line for mod_rewrite. Using the PT flag on
>rewrite rules doesn't help either. The same rewrite
>rules work perfectly with Caucho Resin's mod_caucho.
>It seems as though Tomcat is passed only the original
>URL and not the rewritten URL. I have searched the
>archives and the net but have found nothing that
>solves this problem.
>
>Windows: tomcat 3.2.3; mod_jk.dll 2001-07-17; apache
>1.3.20; sun jdk 1.3.0; windows 2000 sp2
>Linux: tomcat 3.2.3; mod_jk-noeapi.so 2001-07-20;
>apache 1.3.20; ibm jdk 1.3.0; linux 2.2.13
>
>
>__________________________________________________
>Do You Yahoo!?
>Make international calls for as low as $.04/minute with Yahoo! Messenger
>http://phonecard.yahoo.com/
>
>
>