You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by J Channel <jc...@gmail.com> on 2009/04/10 21:41:20 UTC

RewriteRule inside JkMount location

Hi!Apache 2.2.11, mod_jk 1.2.28

httpd.conf:
LoadModule jk_module modules/mod_jk.so
JkOptions   +ForwardURICompat
JkMount /app/* balancer
LoadModule rewrite_module modules/mod_rewrite.so
DocumentRoot /var/www/public_html

.htaccess in docroot:
RewriteEngine On
RewriteCond %{QUERY_STRING} !dyn\=1
RewriteRule ^app/ntd/give.* give.shtml/?%{QUERY_STRING} [L]

I cant get worked this conf on apache 2.2.11, URI http://server/app/ntd* pass
to tomcat omitting RewriteRule. But its ok on apache1.3.33 + mod_jk1.2.14
(even whitout JkOptions +ForwardURICompat, AFAIK its enable by default for
mod_jk <= 1.2.22).

Re: RewriteRule inside JkMount location

Posted by J Channel <jc...@gmail.com>.
> RewriteRule ^myapp/some(.*)  script.shtml%{QUERY_STRING} [L]
> # Line above will be ignored
> JkMount /myapp/* balancer
>
> May be this is just a bug?
>

So, i found that its work only if condition begins with /
RewriteRule ^/myapp/some?(.*)  /script.shtml?%{QUERY_STRING} [L,PT]

Other conditions, not under /myapp/ works without first / ok.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by J Channel <jc...@gmail.com>.
Hi, Rainer!
Thx for you answer, its look like good solution, but anyway ignoring
line BEFORE JkMount - a bit stupid behavior.

RewriteRule ^myapp/some(.*)  script.shtml%{QUERY_STRING} [L]
# Line above will be ignored
JkMount /myapp/* balancer

May be this is just a bug?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by Rainer Jung <ra...@kippdata.de>.
Only one little addition below:

On 11.04.2009 14:19, André Warnier wrote:
> J Channel wrote:
> [...]
> 
> Hi.
> Let me jump in here for a while.
> 
> First, I think it would be clearer (and certainly more efficient), to
> move your Rewrite rules away from a .htaccess file in docroot, and just
> put them in your main Apache configuration files.
> (I suppose that if you have access to the DocumentRoot, you have access
> to the server (or virtual server) *.conf, yes ?)
> 
> Second, I personally find another syntax clearer than JkMount, specially
> when you need to combine it with other rules in Apache.
> The main reason is that indeed, it is not always very clear which kind
> of "priority" JkMount/JkUnMount directives have, vis-a-vis Apache
> Rewrite, <Location> etc..
> 
> So, for example, instead of writing
> JkMount /myapp workername
> JkMount /myapp/* workername
> 
> you can also do it as follows :
> 
> <Location /myapp>
>   SetHandler jakarta-servlet
>   ....
> </Location>
> 
> This is explained here:
> http://tomcat.apache.org/connectors-doc/reference/apache.html
> 
> in the section entitled :
> Using SetHandler and Environment Variables
> 
> Basically, the <Location> section above means that anything
> corresponding to a URI starting with "/myapp" will be passed on to
> Tomcat.  It is thus equivalent to the duo
> JkMount /myapp workername
> JkMount /myapp/* workername
> 
> but, in my view, it gives you more flexibility at the Apache level, and
> also fits better with the Apache "way of things".
> I think it makes the respective priorities of mod_jk and RewriteRules
> clearer, because they are the same as what they are in Apache between
> Rewrite and <Location> blocks.
> For example, if you load the mod_setenvif module in Apache, you can
> exclude some URI's inside of that location using this kind of thing :
> 
> <Location /myapp>
>   SetHandler jakarta-servlet
>   SetEnvIf REQUEST_URI "\.(css|gif|jpg|js|html?)$" no-jk
>   ....
> </Location>
> 
> meaning that URI's for files starting with "/myapp" but ending in one of
> the extensions above will /not/ be passed to Tomcat (but the rest will).

... and you can also use mod_rewrite to set the environment variable
"no-jk", which disables mod_jk forwarding.

> You can also add a second <Location> like
> 
> <Location /myapp/no-tomcat>
>   SetHandler none
>   ....
> </Location>
> 
> so that most things starting with "/myapp" will go to Tomcat, except the
> ones starting with "/myapp/no-tomcat".
> 
> And of course, you can use <Location>, <LocationMatch>, <Files>,
> <FilesMatch> etc.. to similar effect.
> 
> Which seems to me the kind of thing you want.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by André Warnier <aw...@ice-sa.com>.
J Channel wrote:
[...]

Hi.
Let me jump in here for a while.

First, I think it would be clearer (and certainly more efficient), to 
move your Rewrite rules away from a .htaccess file in docroot, and just 
put them in your main Apache configuration files.
(I suppose that if you have access to the DocumentRoot, you have access 
to the server (or virtual server) *.conf, yes ?)

Second, I personally find another syntax clearer than JkMount, specially 
when you need to combine it with other rules in Apache.
The main reason is that indeed, it is not always very clear which kind 
of "priority" JkMount/JkUnMount directives have, vis-a-vis Apache 
Rewrite, <Location> etc..

So, for example, instead of writing
JkMount /myapp workername
JkMount /myapp/* workername

you can also do it as follows :

<Location /myapp>
   SetHandler jakarta-servlet
   ....
</Location>

This is explained here:
http://tomcat.apache.org/connectors-doc/reference/apache.html

in the section entitled :
Using SetHandler and Environment Variables

Basically, the <Location> section above means that anything 
corresponding to a URI starting with "/myapp" will be passed on to 
Tomcat.  It is thus equivalent to the duo
JkMount /myapp workername
JkMount /myapp/* workername

but, in my view, it gives you more flexibility at the Apache level, and 
also fits better with the Apache "way of things".
I think it makes the respective priorities of mod_jk and RewriteRules 
clearer, because they are the same as what they are in Apache between 
Rewrite and <Location> blocks.
For example, if you load the mod_setenvif module in Apache, you can 
exclude some URI's inside of that location using this kind of thing :

<Location /myapp>
   SetHandler jakarta-servlet
   SetEnvIf REQUEST_URI "\.(css|gif|jpg|js|html?)$" no-jk
   ....
</Location>

meaning that URI's for files starting with "/myapp" but ending in one of 
the extensions above will /not/ be passed to Tomcat (but the rest will).

You can also add a second <Location> like

<Location /myapp/no-tomcat>
   SetHandler none
   ....
</Location>

so that most things starting with "/myapp" will go to Tomcat, except the 
ones starting with "/myapp/no-tomcat".

And of course, you can use <Location>, <LocationMatch>, <Files>, 
<FilesMatch> etc.. to similar effect.

Which seems to me the kind of thing you want.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by J Channel <jc...@gmail.com>.
I found that its work ok with httpd.conf like this:
...
JkMount /app/* balancer
JkUnMount /app/ntd/* balancer
...

But this is not very well cause i need to add many exception pathes
like this to httpd.conf :(
I just need to have mod_rewrite directives with more priority than JkMount.
Just like in apache1.3+mod_jk1.2.4
How can i tune this?

> I send URL http://testsite.net/app/ntd/give?someparams=value
> And i give a tomcat page "Sorry, we have no such page" instead of my
> http://testsite.net/give.shtml?someparams=value page.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by J Channel <jc...@gmail.com>.
2009/4/11 Rainer Jung <ra...@kippdata.de>:
> On 10.04.2009 23:24, J Channel wrote:
>> 2009/4/11 Rainer Jung <ra...@kippdata.de>
>>> On 10.04.2009 21:41, J Channel wrote:
>>>> Hi!Apache 2.2.11, mod_jk 1.2.28
>>>>
>>>> httpd.conf:
>>>> LoadModule jk_module modules/mod_jk.so
>>>> JkOptions   +ForwardURICompat
>>>> JkMount /app/* balancer
>>>> LoadModule rewrite_module modules/mod_rewrite.so
>>>> DocumentRoot /var/www/public_html
>>>>
>>>> .htaccess in docroot:
>>>> RewriteEngine On
>>>> RewriteCond %{QUERY_STRING} !dyn\=1
>>>> RewriteRule ^app/ntd/give.* give.shtml/?%{QUERY_STRING} [L]
>>>>
>>>> I cant get worked this conf on apache 2.2.11, URI http://server/app/ntd* pass
>>>> to tomcat omitting RewriteRule. But its ok on apache1.3.33 + mod_jk1.2.14
>>>> (even whitout JkOptions +ForwardURICompat, AFAIK its enable by default for
>>>> mod_jk <= 1.2.22).
>>> It would be nice, if you would tell us, which URL you send, what you
>>> expect to happen, and what happens instead.

I send URL http://testsite.net/app/ntd/give?someparams=value
And i give a tomcat page "Sorry, we have no such page" instead of my
http://testsite.net/give.shtml?someparams=value page.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by Rainer Jung <ra...@kippdata.de>.
On 10.04.2009 23:24, J Channel wrote:
> 2009/4/11 Rainer Jung <ra...@kippdata.de>
>> On 10.04.2009 21:41, J Channel wrote:
>>> Hi!Apache 2.2.11, mod_jk 1.2.28
>>>
>>> httpd.conf:
>>> LoadModule jk_module modules/mod_jk.so
>>> JkOptions   +ForwardURICompat
>>> JkMount /app/* balancer
>>> LoadModule rewrite_module modules/mod_rewrite.so
>>> DocumentRoot /var/www/public_html
>>>
>>> .htaccess in docroot:
>>> RewriteEngine On
>>> RewriteCond %{QUERY_STRING} !dyn\=1
>>> RewriteRule ^app/ntd/give.* give.shtml/?%{QUERY_STRING} [L]
>>>
>>> I cant get worked this conf on apache 2.2.11, URI http://server/app/ntd* pass
>>> to tomcat omitting RewriteRule. But its ok on apache1.3.33 + mod_jk1.2.14
>>> (even whitout JkOptions +ForwardURICompat, AFAIK its enable by default for
>>> mod_jk <= 1.2.22).
>> It would be nice, if you would tell us, which URL you send, what you
>> expect to happen, and what happens instead.
>>
> 
> Now all URL under app/* just pass out to tomcat.
> I expect redirection to give.shtml by RewriteRule as it works in
> apache1.3 with same configuration.
> 
>> General comments:
>>
>> - do not use any Forward JkOptions unless you are sure you need them and
>> understand the implications. So I suggest you drop the respective line
> 
> Ok, drop it, no changes.
> 
>> - if you want mod_jk to be called even when mod_rewrite interfered with
>> the URL, you need to add the PT flag to the rule (OT=pass through), so
>> switch from "[L]", to "[L,PT]".
> 
> I have no problem with pass through, i have problem with ignoring my
> rewrite directives under /app/*

So we are back to:

>> It would be nice, if you would tell us, which URL you send, what you
>> expect to happen, and what happens instead.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by J Channel <jc...@gmail.com>.
2009/4/11 Rainer Jung <ra...@kippdata.de>
>
> On 10.04.2009 21:41, J Channel wrote:
> > Hi!Apache 2.2.11, mod_jk 1.2.28
> >
> > httpd.conf:
> > LoadModule jk_module modules/mod_jk.so
> > JkOptions   +ForwardURICompat
> > JkMount /app/* balancer
> > LoadModule rewrite_module modules/mod_rewrite.so
> > DocumentRoot /var/www/public_html
> >
> > .htaccess in docroot:
> > RewriteEngine On
> > RewriteCond %{QUERY_STRING} !dyn\=1
> > RewriteRule ^app/ntd/give.* give.shtml/?%{QUERY_STRING} [L]
> >
> > I cant get worked this conf on apache 2.2.11, URI http://server/app/ntd* pass
> > to tomcat omitting RewriteRule. But its ok on apache1.3.33 + mod_jk1.2.14
> > (even whitout JkOptions +ForwardURICompat, AFAIK its enable by default for
> > mod_jk <= 1.2.22).
>
> It would be nice, if you would tell us, which URL you send, what you
> expect to happen, and what happens instead.
>

Now all URL under app/* just pass out to tomcat.
I expect redirection to give.shtml by RewriteRule as it works in
apache1.3 with same configuration.

> General comments:
>
> - do not use any Forward JkOptions unless you are sure you need them and
> understand the implications. So I suggest you drop the respective line

Ok, drop it, no changes.

> - if you want mod_jk to be called even when mod_rewrite interfered with
> the URL, you need to add the PT flag to the rule (OT=pass through), so
> switch from "[L]", to "[L,PT]".

I have no problem with pass through, i have problem with ignoring my
rewrite directives under /app/*

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RewriteRule inside JkMount location

Posted by Rainer Jung <ra...@kippdata.de>.
On 10.04.2009 21:41, J Channel wrote:
> Hi!Apache 2.2.11, mod_jk 1.2.28
> 
> httpd.conf:
> LoadModule jk_module modules/mod_jk.so
> JkOptions   +ForwardURICompat
> JkMount /app/* balancer
> LoadModule rewrite_module modules/mod_rewrite.so
> DocumentRoot /var/www/public_html
> 
> .htaccess in docroot:
> RewriteEngine On
> RewriteCond %{QUERY_STRING} !dyn\=1
> RewriteRule ^app/ntd/give.* give.shtml/?%{QUERY_STRING} [L]
> 
> I cant get worked this conf on apache 2.2.11, URI http://server/app/ntd* pass
> to tomcat omitting RewriteRule. But its ok on apache1.3.33 + mod_jk1.2.14
> (even whitout JkOptions +ForwardURICompat, AFAIK its enable by default for
> mod_jk <= 1.2.22).

It would be nice, if you would tell us, which URL you send, what you
expect to happen, and what happens instead.

General comments:

- do not use any Forward JkOptions unless you are sure you need them and
understand the implications. So I suggest you drop the respective line

- if you want mod_jk to be called even when mod_rewrite interfered with
the URL, you need to add the PT flag to the rule (OT=pass through), so
switch from "[L]", to "[L,PT]".

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org