RE: [users@httpd] JKMount based on URL query parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I liked Noah's idea, but used it in a slightly different fashion.
Rewriting a query string to an all-path type of request is not a
solution for two reasons.

1. You do not want to change the context/query string when handing out
to tomcat.
2. It gets tricky as you mentioned, or even not possible when you want
to look at more than one element in the query to make the "which worker"
decision.

This is what I have used. Instead of converting the query string to an
all-path request, I am preserving the query string, but inserting a
unique 'dummy' path so that <Location> can recognize that the request
matched a specific rule. In this block, I am converting the request back
to the original by stripping the 'dummy' path and then assigning it to a
tomcat worker. 

RewriteCond %{QUERY_STRING} ^(.*)location=NY(.*)$
RewriteRule ^/abc/Team http://localhost/abc/dummy1/Team?%1location=NY%2
RewriteCond %{QUERY_STRING} ^(.*)location=NJ(.*)$
RewriteRule ^/abc/Team http://localhost/abc/dummy2/Team?%1location=NJ%2

<Location /abc/dummy1/*>
    RewriteCond %{QUERY_STRING} ^(.*)location=NY(.*)$
    RewriteRule ^.* http://localhost/abc/Team?%1location=NY%2
    JKMount worker1
</Location>

<Location /abc/dummy2/*>
    RewriteCond %{QUERY_STRING} ^(.*)location=NJ(.*)$
    RewriteRule ^.* http://localhost/abc/Team?%1location=NJ%2
    JKMount worker2
</Location>

It is still not a clean solution as it involves an additional rewrite,
but it works. All this could have been avoided if <LocationMatch> can
handle the query string as well, apart from the path.  On the contrary,
one advantage I see with this approach is, you have the flexibility to
specify more than one RewriteCond for every RewriteRule.

If you notice, the original path & query string gets preserved, but not
the servername as I added the prefix "http://localhost";. I looked at the
mod_rewrite doc at http://httpd.apache.org/docs/mod/mod_rewrite.html and
the following substitution given in the doc does not work.

Given rule                                      Substitution
-----------                                     --------------
^/somepath(.*) /otherpath$1                     /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1      /otherpath/pathinfo

Though both the rules is said to result in the same substitution for
per-server configuration, only the second one seem to work. 

Is anybody successful in getting the first rule to work in httpd.conf?

I appreciate your response. -Arun


-----Original Message-----
From: Noah [mailto:sitz@xxxxxxxxxxxx] 
Sent: Friday, May 06, 2005 11:58 AM
To: users@xxxxxxxxxxxxxxxx
Subject: Re: [users@httpd] JKMount based on URL query parameters

On Fri, May 06, 2005 at 09:50:49AM -0700, Govindarajulu, Arun wrote:
> Hello,
> 
> I am trying to assign requests to specific tomcat workers based on
query
> strings in the URL.
> 
> For example,
> 
>     http://localhost/abc/Team?name=xyz&location=NY should be assigned
to
> worker1 and 
>     http://localhost/abc/Team?name=xyz&location=NJ should be assigned
to
> worker2
> 
> Is this possible? I tried the following, but it doesn't work.
> 
>     <LocationMatch /abc/Team*location=NY*>
>        JkMount worker1
>     </LocationMatch>
> 
>     <LocationMatch /abc/Team*location=NJ*>
>        JkMount worker2
>     </LocationMatch>

Caveat: I've not tried this; this is all theory

You may be able to mod_rewrite this:

<Location /abc/Team/location/NY>
    JKMount worker1
</Location>

<Location /abc/Team/location/NJ>
    JKMount worker2
</Location>

RewriteEngine on

#
# verify that you have a query string in the request
RewriteCond %{QUERY_STRING} .

#
# snag the value of 'location' and store it in %1;
# optionally use the case insensitive flag ('[NC]')
# if you think 'location' (or it's value) might be
# in mixed-case.
RewriteCond %{QUERY_STRING} location=([^&]+) [NC]

#
# Rewrite
RewriteRule ^/abc/Team /abc/Team/location/%1 [L]


This will internally rewrite the request from a query string type of
request to an all-path type of request; you then set up <Location>
blocks for each area. Things get a bit trickier if you need to make the
'which worker' decision based on more than one element in the query
string, since the order of the query string elements may be different
and mod_rewrite is regex based. Also note that since apache modules are
called in reverse order (bottom to top in the config file), mod_rewrite 
will need to appear *below* mod_jk in your LoadModule list, since the
URL needs to be rewritten before the request is handed off to mod_jk.

In /theory/, this will work. In practice, I can only vouch for the
mod_rewrite code. I'd certainly be interested in knowing the outcome,
though. =)

(note: if any of this doesn't make sense, check out the mod_rewrite docs
at http://httpd.apache.org/docs/mod/mod_rewrite.html)

--n

-- 
"Any system shall not harm your content or, through 
inaction, allow your content to come to harm."
                            - Jeff Raskin

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server
Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux