[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1450
  • Last Modified:

How do I redirect JSP webapps handled by Tomcat to another server/domain?

I am planning a migration from our current server (Sun OS 5.8) to our new server (Redhat 4 64-bit).  I have recreated a similar infrastructure on the new server - Apache2, Tomcat, MySQL, Twiki.

On the current server I am running Apache 2.0.49 and Tomcat 5.0.24
On the new server I am running Apache 2.0.52 and Tomcat 5.5.25
On each machine I am using default ports: port 80 for Apache and 8080 for Tomcat.

All the pieces on the new server are working fine and accessing stuff only in the new environment.

My problem is to seamlessly redirect any links/references to the old domain/server to the new one, for both Apache2 (port 80) and for Tomcat (port 8080).

On the old server, I know I can add a redirect in apache's httpd.conf to redirect all apache
requests (for documents and cgi-bin scripts) to the new server and that seemed to work fine:
AllowOverride All
Redirect permanent / http://myweb.newdomain.com/

Tomcat is running and handling all requests sent to http://myweb.olddomain.com:8080/...
What I need is to also redirect those tomcat webapp requests.  And I just want the simplest, easiest way to do so.  Speed or load is not an issue.
I want all of these type of references to redirect smoothly:
from     http://myweb.olddomain.com:8080/   to    http://myweb.newdomain.com:8080
http://myweb.olddomain.com:8080/mydir       to    http://myweb.newdomain.com:8080/mydir
from    http://myweb.olddomain.com:8080/mydir/foo.jsp  
to        http://myweb.newdomain.com:8080/mydir/foo.jsp
from    http://myweb.olddomain.com:8080/mydir/foo.jsp?filter=XXX      
to        http://myweb.newdomain.com:8080/mydir/foo.jsp?filter=XXX

I've searched forums and found lots of suggestions using a variety of techniques,
but have not been successful.  I'm not very familiar with mod_rewrite, mod_jk, 301 redirection, etc. but am learning slowly.
I was also experimenting with Paul Tucke's URLRewriteFilter, but couldn't get that to work
(it would not match any of my "from" expressions).
It seems to me that this shouldn't be that complicated hard, but I'm finding it very confusing and frustrating.  I think I should be able to do it perhaps using mod_rewrite, but I get tangled trying to determine specifically what I need to add to accomplish that.

What would you recommend as the easiest way to get all of these redirections to occur
from an old server in one domain to a new server in another domain?

I've reverted to what was the original conf files for apache and for tomcat (without any of my additions).
When I start up tomcat, I see the following in the catalina.out file:
Nov 17, 2008 3:44:49 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Nov 17, 2008 3:44:49 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Nov 17, 2008 3:44:49 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/22  config=null

Thanks!
0
bohunk24
Asked:
bohunk24
1 Solution
 
caterham_wwwCommented:
> perhaps using mod_rewrite

If myweb.olddomain.com:8080 is a tomcat application server, you can't use apache's modules here. Or does myweb.olddomain.com:8080 connect to tomcat?

Did you already try the UrlRewriteFilter with


<rule>
<name>redirect olddomain</name>
<condition name="host" operator="notequal">myweb\.newdomain\.com:8080</condition>
<from>^/(.*)</from>
<to type="redirect">http://myweb.newdomain.com:8080/$1</to>
</rule>

Open in new window

0
 
bohunk24Author Commented:
Thank you Caterham!  That was the clue I needed!
I had tried all sorts of permutations on URL rewrite rules.  However, I didn't include any conditions since the documentation led me to believe I didn't need them and that I could do everything in the regular expression of the "from".
Your suggestion worked perfectly for webapps/ROOT.  I did need to modify it slightly for the other subdirectories in webapps.  While I was able to use the same <from> in the urlrewrite.xml, but had to add the directory name to the <to>, e.g. <to type="redirect">http://myweb.newdomain.com:8080/subdir/$1</to
P.S. In answer to your question, yes, myweb.olddomain.com:8080 connects to Tomcat.  I don't need apache for that.  
 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now