Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm doing a path rewrite to set and environment variable that will cause mod_jk to use a specific JBoss server. Works perfectly with any of the application paths.

When I try our monitoring servelet (does a simple db get to prove the stack is operational), it matches the rewrite, does the rewrite, sets the env var, but then fails to actually process the URL a second time.

Why the inconsistent behavior of the second trip through the rewrite engine?

Pattern is that if /workername/ is prepended to the path, it will remove but use that value as the JK_WORKER_NAME for the mod_jk mount.

Example config:

SetHandler jakarta-servlet  
SetEnv JK_WORKER_NAME mexico

RewriteEngine on
RewriteRule ^/(mexico[1-2])/(.*)$ /$2  [E=JK_WORKER_NAME:$1,L] 

(mod_jk workers are named mexico1 and mexico2)

A hit to https://hostname/mexico2/public/gateway.sf get a rewrite and then a second pass through the rewrite engine, processed by mod_JK and passed to the apps server. All good, see log (scroll right for good bits)

10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (2) init rewrite engine with requested uri /mexico2/public/gateway.sf
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (3) applying pattern '.*' to uri '/mexico2/public/gateway.sf'
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (4) RewriteCond: input='GET' pattern='^TRACE' => not-matched
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (3) applying pattern '^/(mexico[1-2])/(.*)$' to uri '/mexico2/public/gateway.sf'
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (2) rewrite '/mexico2/public/gateway.sf' -> '/public/gateway.sf'
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (2) local path result: /public/gateway.sf
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (2) prefixed with document_root to /data/publisher/webdav/images/notice/public/gateway.sf
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde6fae0/initial] (1) go-ahead with /data/publisher/webdav/images/notice/public/gateway.sf [OK]
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde84180/initial] (2) init rewrite engine with requested uri /public/gateway.sf
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde84180/initial] (3) applying pattern '.*' to uri '/public/gateway.sf'
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde84180/initial] (4) RewriteCond: input='GET' pattern='^TRACE' => not-matched
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde84180/initial] (3) applying pattern '^/(mexico[1-2])/(.*)$' to uri '/public/gateway.sf'
10.1.1.163 - - [26/Aug/2013:14:10:44 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde84180/initial] (1) pass through /public/gateway.sf

A hit to https://hostname/mexico1/monitorme.mmm also matches the condition and gets rewrite, but then never gets a second pass through the engine and apache tries to server that path from the doc root. All hits are passed through to JBoss, there are no documents in the doc root. Thus I get a page not found.

10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (2) init rewrite engine with requested uri /mexico1/monitorme.mmm
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (3) applying pattern '.*' to uri '/mexico1/monitorme.mmm'
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (4) RewriteCond: input='GET' pattern='^TRACE' => not-matched
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (3) applying pattern '^/(mexico[1-2])/(.*)$' to uri '/mexico1/monitorme.mmm'
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (2) rewrite '/mexico1/monitorme.mmm' -> '/monitorme.mmm'
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (2) local path result: /monitorme.mmm
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (2) prefixed with document_root to /data/publisher/webdav/images/notice/monitorme.mmm
10.1.1.163 - - [26/Aug/2013:14:12:17 --0400] [publisher.internal.test.hnw.com/sid#2ad8c96bc310][rid#2ad8bde71af0/initial] (1) go-ahead with /data/publisher/webdav/images/notice/monitorme.mmm [OK]
share|improve this question

1 Answer 1

It's a bit surprising that the first run works if you use the example RewriteRule above. I thought L was suppose to stop execution when it hit. I think you should use N instead of L.

I did not try it and can't call myself an mod_rewrite expert. :-)

last|L : Stop the rewriting process immediately and don't apply any more rules. Especially note caveats for per-directory and .htaccess context (see also the END flag).

next|N : Re-run the rewriting process, starting again with the first rule, using the result of the ruleset so far as a starting point.

share|improve this answer
    
Thanks for turning me on to the N flag. I too would think that would do it and tried, but it didn't do it. I eventually tried the Pass Through [PT] and though a bit sloppy, it does work. The URL in the browser doesn't change, but in the logging it shows the rewrite does happen. And more importantly, mod_jk and jboss recognize that it has and serves the correct page/servlet. –  8None1 Sep 5 '13 at 18:43
    
The key difference I'm seeing is that with N or L, the app URL goes through twice and ends with a "pass through /public/gateway.sf". The monitorme.mmm servlet ends with "go-ahead with {redacted path to docroot} [OK]". If I use PT, it seems to force the "pass through" at conclusion. –  8None1 Sep 5 '13 at 18:51
    
If you find out a solution that is good enough for you, please answer your own question for future references. Plus I am interested to see what the solution is. :-) –  Qben Sep 6 '13 at 6:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.