Mod_jk conflicts with mod_rewrite

Apache and Tomcat work for me, and I use mod_jk to bind them. I have a Tomcat worker called "tc1" and the following setting on my VirtualHost :

 JkMount /* tc1 JkUnMount /*.png tc1 JkUnMount /*.gif tc1 JkUnMount /*.css tc1 JkUnMount /*.js tc1 

Thus, Tomcat serves all requests except those for static files.

Now I want to use mod_rewrite and do something very simple, for example:

 RewriteEngine On RewriteRule ^/foo$ /bar [L] 

rewrite the dynamic pageview on "/ foo" to "/ bar", but this will not work because all the URLs processed by mod_rewrite do not end with mod_jk .

I read the Apache Tomcat Connector documentation and tried all of JkOptions , but nothing changed.

Does anyone know how to solve this?

Does ordering and mod_jk and mod_rewrite roles in URL processing?

thanks

+6
tomcat apache mod-rewrite mod-jk
source share
1 answer

This is strange because, by default, the RewriteRule sends redirects on the client side, so the client must make a second / bar request, which should be caught by your JkMount . Does your access log show a request for /foo and a request for /bar as well?

Try this rule:

 RewriteRule ^/foo$ /bar [PT,L] 

"PT" means "pass-through" and is a rewriting field that allows you to mutate the URL in place and allows other modules to browse without sending a redirect.

+12
source share

All Articles