Wednesday, February 3, 2010

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 and to the a certain application that I call it "app" here. My task was clear; indeed, I had to implement below mapping:
  • ....
  • ....
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:
<name>Changing Domain</name>
<condition name="host" operator="equal"></condition>
<to type="permanent-redirect">$1</to>

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 I have got my routing goals on Tomcat 6.0 and JBoss 4.2.2 with this simple URL re-writing.


  1. This is an awesome guide, i was looking for the same solution for a month.

    Thanks a lot!

  2. Hi Amir,

    First of all, congratulations for this article!

    Could you post or send me how do you set de config inside the web.xml file ?

    You did like this?



    Thank you very much!