Discussion:
Apache mod_jk SetEnvIf negative look ahead not working
as2
2009-06-22 04:10:47 UTC
Permalink
Hi,

I am trying to add a rule .. some thing like this


<LocationMatch "/app/">
SetHandler jakarta-servlet
SetEnvIf REQUEST_URI "\.(jsp|htm?)$" JK_WORKER_NAME=default
SetEnvIf REQUEST_URI ^(/app/dir/([^/]*)/(?!jsp)) no-jk

</LocationMatch>

I am having problem with this line
SetEnvIf REQUEST_URI ^(/app/dir/([^/]*)/(?!jsp)) no-jk

I want to use no-jk only when the request URI does not contain
/app/dir/*/jsp/ path. This works with ruby, but now working with apache
mod_jk. Is there a way to make negative expression work in mod_jk

And also I would like to add another expression that checks if the folder
(that does not contain /jsp/ folder) contains file with jsp extenstion so
that use JK_WORKER_NAME=$1 instead of no-jk

Thanks
--
View this message in context: http://www.nabble.com/Apache-mod_jk--SetEnvIf-negative-look-ahead-not-working-tp24141543p24141543.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
André Warnier
2009-06-22 08:58:30 UTC
Permalink
Post by as2
Hi,
I am trying to add a rule ..
Try this :

# First, all URLs that start with "/app/" and end in either .jsp, .htm
# or .html are forwarded to Tomcat
<LocationMatch "^/app/.+\.(jsp|html?)$">
SetHandler jakarta-servlet
</LocationMatch>

# But, we don't want that if it's inside of "/app/dir/"
<LocationMatch "^/app/dir/">
SetHandler none
</LocationMatch>

# Except if it is inside of a "/jsp/" subdir of "/app/dir",
# then we do want it anyway
<LocationMatch "^/app/dir/.*/jsp/">
SetHandler jakarta-servlet
</LocationMatch>

You may need to modify that a bit, according to what you want exactly
(which is not so clear in your original question).

But the base is :
- <Location> and <LocationMatch> are applied one after the other, in
the order in which they appear in the configuration file.
(See : http://httpd.apache.org/docs/2.2/sections.html )
- "SetHandler jakarta-servlet" makes it so that all applicable URLs are
proxied to Tomcat
- "SetHandler none" cancels the effect of a previous "SetHandler
jakarta-servlet" and returns to the default Apache handling.
(See : http://httpd.apache.org/docs/2.2/mod/core.html#sethandler )
Rainer Jung
2009-06-23 15:05:40 UTC
Permalink
Hi,
Post by as2
Hi,
I am trying to add a rule .. some thing like this
<LocationMatch "/app/">
SetHandler jakarta-servlet
SetEnvIf REQUEST_URI "\.(jsp|htm?)$" JK_WORKER_NAME=default
SetEnvIf REQUEST_URI ^(/app/dir/([^/]*)/(?!jsp)) no-jk
</LocationMatch>
I am having problem with this line
SetEnvIf REQUEST_URI ^(/app/dir/([^/]*)/(?!jsp)) no-jk
I want to use no-jk only when the request URI does not contain
/app/dir/*/jsp/ path. This works with ruby, but now working with apache
mod_jk. Is there a way to make negative expression work in mod_jk
Did you try with the latest jk version (1.2.28)?

Not sure, what exactly works with ruby, but mod_jk doesn't know anything
about SetEnvIf and negative look ahead. It only checks, whether the
"no-jk" Apache environment variable is set, and if so, it doesn't
forward the request and instead lets Apache handle it itself.

You can check the value of "no-jk" by adding %{no-jk}e to your LogFormat
used in the CustomLog.
Post by as2
And also I would like to add another expression that checks if the folder
(that does not contain /jsp/ folder) contains file with jsp extenstion so
that use JK_WORKER_NAME=$1 instead of no-jk
You can use mod_rewrite for such things. Mod_rewrite can check for file
existence and can also use back references when setting env vars.

Regards,

Rainer

Loading...