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

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

 



On Thu, May 12, 2005 at 01:47:45PM -0700, Govindarajulu, Arun wrote:
> 
> I liked Noah's idea, but used it in a slightly different fashion.

[snip]

> 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. 

*nod* Yep, that'll work just fine. You may (if you've not already) want
to make the dummpy pathnames have some text in common with the request,
just for self-documenting purposes.

> 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>

Mmm. This will actually issue a 302 redirect back to the client, which
may or may not be what you want. If you don't specify the
'http://hostname' portion, everything should happen transparently behind
the scenes. Also note that the capturing you're using in unnecessary,
since you can do this...

RewriteCond %{QUERY_STRING} ^.*location=NY.*$
RewriteRule ^/abc/Team /abc/dummy1/Team

...and the query string will be automagically appended to the target
URL. The other problem with the above is that '.*' may wind up being
more greedy than you had anticipated, since:

RewriteCond %{QUERY_STRING} ^.*location=NY.*$

...will also match on:

/abc/Team?foo=bar&my_location=NY&location=NJ

...which probably isn't what you want. Yes, the example is a bit
contrived, but I prefer to be paranoid. =)  Additionally, I've heard (but
never actually confirmed) that regexes with '.*' can be slower to
execute; this is why I try to use something like this:

RewriteCond %{QUERY_STRING} (^|&)location=[^&]+ [NC]


Finally, although it's implied by the syntax, it's good practice to
terminate each RewriteRule with the 'L' flag, unless you are explicitly
leaving it out.

--n

-- 
When the need arises -- and it does -- you must be able to shoot your own 
dog. Don't farm it out -- that doesn't make it nicer, it makes it worse.
                                        --Robert A. Heinlein

---------------------------------------------------------------------
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