0

I have two different domain & sub domain.

For example :-

Domain 1 :- example1.com IP :- XXX.XX.XX.201 Domain 2 :- example2.com IP :- XXX.XX.XX.202 (This is a virtual hosting on above IP addr XXX.XX.XX.201)

I am also using sub-domains for the same like,

Domain 1 :- test.example1.com IP :- XXX.XX.XX.201 Domain 2 :- test.example2.com IP :- XXX.XX.XX.202 (This is a virtual hosting on above IP addr XXX.XX.XX.201)

I have to access the application in such way that if i access example.com it will redirect to me app1 and test.example.com will redirect mi to app2.

I have done some configuration related to this in my server.xml of tomcat.

<Host name="localhost" appBase="webapps"></Host>

<Host name="example2.com" appBase="webapps_example2"> <Alias>test.example2.com</Alias> </Host>

If i hit URL like,

1. http://example2.com -> I want to show an application app1

2. http://test.example2.com -> I want to show an application app2

I have deployed app1 in webapps_example2 & when i hit any of the above URL .. both the URL redirecting to the same app1. Where should i deploy my app2 so it will be accessible by above url no 2.

Note :- test.example.com is a just sample url & sub-domains may be change anytime so i can't put separate virtual host for entry & webapps folder for each sub domain. app1 is simple html website & app2 is an J2EE application

Can anyone help me for doing this ???

Thanks in advance...

Sanket Dosi
  • 195
  • 1
  • 4
  • 15

1 Answers1

0
<Connector port="80" ... />
<Engine name="Catalina" defaultHost="localhost">
  <Host name="example.com" appBase="webapps-example"></Host>

  <Host name="test.example.com" appBase="webapps-test.example"></Host>
</Engine>

Now, move app1 to webapps-example/ROOT (case matters) (you ought to have webapps-example/ROOT/WEB-INF/web.xmlfor example) and moveapp2towebapps-test.example/ROOT`.

That ought to do it for example.com. You can do the same for example2.com, etc.

If you want a hostname to map to a single web application, you must name the web application ROOT and put it into its own "webapps" (appBase) directory. You will have to duplicate the <Host> configuration for every virtual host you want to support.

If you are more relaxed about your requirements, you can do things in a more flexible way without having to define all those <Host> elements.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • **Thanks Christopher**, Its working fine with your solution & its full-filling my requirements about accessing application with specific URL. – Sanket Dosi Oct 27 '14 at 09:37