Apache HTTPD 2.2 + Tomcat 6: How to redirect a rewrite URL?

Hi,

What seemed a simple request has turned into a real pain, let me explain.

Currently the webserver is accessed via

          <webaddress>:5599/

Web Server Conf (in the httpd-ssl.conf within the VirtualHost section)

ProxyPass / ajp://<webaddres>/app/
ProxyPassReverse / ajp://192.168.0.202:5599/app/
RewriteCond %{REQUEST_URI} (.)
RewriteRule ^/app/(.
)$ $1

It get’s deeper!

As you can see it uses the Tomcat AJP Connetor to the /app applicaition.
So far so good? The Application uses a mixture of plain Servlets and Struts2 (don’t ask!)

The issue is when a Struts2 page is access with a submit/form, it generates a link “/app/aMessageName/NewPOPEICNLPForm”

Generated HTML from Struts2
<form id=“entryForm” name=“NewPOPEICNLPForm” onsubmit=“return true;” action=“/app/aMessageName/NewPOPEICNLPForm.action” method=“POST”>

Problem: :confused:
In the access logs I get /app/aMessageName/NewPOPEICNLPForm.action HTTP/1.1" 400 226

In the rewrite log:-
192.168.0.181 - - [13/Mar/2009:15:31:06 +0000] [yellow9/sid#a8f72f92][rid#8fe21e8/initial] (2) init rewrite engine with requested uri /app/aMessageName/NewPOPEICNLPForm.action
192.168.0.181 - - [13/Mar/2009:15:31:06 +0000] [yellow9/sid#a8f72f92][rid#8fe21e8/initial] (3) applying pattern ‘^/app/(.*)$’ to uri ‘/app/aMessageName/NewPOPEICNLPForm.action’
192.168.0.181 - - [13/Mar/2009:15:31:06 +0000] [yellow9/sid#a8f72f92][rid#8fe21e8/initial] (2) rewrite ‘/app/aMessageName/NewPOPEICNLPForm.action’ -> ‘aMessageName/NewECNPForm.action’
192.168.0.181 - - [13/Mar/2009:15:31:06 +0000] [yellow9/sid#a8f72f92][rid#8fe21e8/initial] (2) local path result: aMessageName/NewPOPEICNLPForm.action

So in summary,
We access the Appache webserver which in turns proxy reverse to the Tomcat 6 server. Links generated by Struts append /app/ to them.

We can get around this by moving the app folder into ROOT but I am sure there is a way around this?

Sorry for the v.long question but more is better (I am told!)

Kind Regards, Ken

Hi Ken,

Sorry, I don’t know TomCat but Apache’s mod_rewrite is my forte so I’ll comment on that:

[COLOR=Red]RewriteCond &#37;{REQUEST_URI} (.*)[/COLOR]
RewriteRule ^[COLOR=Red]/[/COLOR]app/(.*)$ $1
  1. Red block one (the RewriteCond) does NOTHING (except to create a %1 variable)

  2. The leading / is a leftover from Apache 1.x. I know that mod_rewrite works a bit differently in .htaccess than in VirtualHost but try omitting this if you’re not matching (you are - so leave this as something to look at if all else fails).

  3. Your mod_rewrite block statement lacks a Last flag so, if there is other code afterward, this will be ANDed with the next statement.

  4. Most importantly, this appears to be better suited a core feature, i.e., mod_alias’s Redirect 301 / /app/ .

Regards,

DK

First off thanks so much for the reply (it’s people like you that give the world of IT a good name - crawl mode ended!) :slight_smile:

Okay I will try that when I am in next with this client. Is the mod_rewrite geared more towards Peral RE ? Mind you not too much difference.

Anway, my follow up thought is what is actually happening at the Proxypass and reverse that effects the redirection?

i.e.

on the way in user clicks on a link with://localmachine:9933/Servlet/MyAction.do?Test=test&

The apache looks for the ProxyPass and forwards it to the port.
On the way back the reversePass is executed and then finally the new url is served.

So it goes to appache twice before serving the page?

P.S. Anywhere I can get more information on how the route of the Apache to Tomcat is done?

Many Thanks again.
Ken (UK)

“I love A Patchy Web Server” :slight_smile:

Hi Ken,

:blush:

mod_rewrite is like using a shell: you’re directing Apache to do something that’s not in its httpd.conf instruction set.

Sorry, I don’t know about ProxyPass but don’t believe that it should directly affect what mod_rewrite is doing. I would think that it only “goes to Apache” the first time.

I think that Apache.org would have a subdomain for tomcat so I’d try http://tomcat.apache.org for Tomcat information.

Regards,

DK

Thanks for the info so far. Hopefully tomorrow when I am next at the clients site I can check these out.
Thanks, Ken
:slight_smile:

Just to let you know that it turns out that the application had a mixture of hardcode urls and getbase methods and straightforward root calls.
i.e. without the mod_rewrite_html it won’t work the way I want it to.
Solution: deploy it in tomcat as ROOT!
And works fine now.

Thanks anyway
:slight_smile: