Routing multiple domains to an application using URL rewrite filter in JSP contatiners and JEE application servers

My client has assigned two separated domain address to a certain IP address. My client was going to map two domain addresses to an application which hosted on JBoss 4.2.2.
Each domain address should route requests to some certain pages of the application. I had to assign firstdomain.com and seconnddomain.com to the a certain application that I call it “app” here. My task was clear; indeed, I had to implement below mapping:
  • http://firstdomain.com …. http://1.2.3.4/app/first.html
  • http://seconddomain.com …. http://1.2.3.4/app/repo/second.html
As you can see, IP and application name are the common parts and inner paths goes different. I used UrlRewriteFilter that simulates Apache rewrite URL method in JSP containers and JEE app servers. It is just enough to follow the instruction. UrlRewriteFilter has a vast of samples but I have not found the proper rule that maps different url on a certain IP address. So, after some tries and errors; finally, below rule worked for me:
<rule>
<name>Changing Domain</name>
<condition name=”host” operator=”equal”>firstdomain.com</condition>
<from>^/(.*)</from>
<to type=”permanent-redirect”>http://1.2.3.4/app/repo/second.html$1</to>
</rule>
This is just enough to add above rule into the urlrewrite.xml.
first.html is the default page. So you just need to handle the request which comes to the seconddomain.com. I have got my routing goals on Tomcat 6.0 and JBoss 4.2.2 with this simple URL re-writing.
This entry was posted in Java, Linux, Networking. Bookmark the permalink.

Leave a Reply