1

I have a tomcat web-app in the webapps/ROOT folder. And it can be accessed using http://myapp.mydomain.com.

But there's a requirement to bind http://mypage1.mydomain.com to the html page webapps/ROOT/mypage1.html

and

to bind http://mypage2.mydomain.com to the html page webapps/ROOT/mypage2.html.

How can I bind those names to the different pages in same app? Is it something related to virtual hosting in tomcat? Or can it be simply done using my domain name hosting providers settings?

Thanks in advance.

1

1 Answer 1

1

Tomcat fully supports virtual hosting via multiple declarations; however, unless I'm mistaken each webapp is deployed separately on each virtual host. In other words, you would have the same WAR deployed twice, once on mypage1.mydomain.com and once on mypage2.mydomain.com. This is not a good idea, especially if you need to share session data across different requests inside the application.

Another ugly approach is to issue redirections (302) from requests to mypage1 and mypage2 to the "canonical" name, myapp. This increases load on your servers but is a quick and dirty working solution as long as your clients support redirections.

Finally, the clean approach may be to set up a webserver in front of your Tomcat and rewrite the request, and Tomcat never sees mypage1 and mypage2 in the hostname. I don't recall off the top of my head how to use mod_rewrite to change the host, but is should be possible.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Shay, I'll try your suggested workarounds if there's no direct way. mod_rewrite should be a good way but I'm not sure how to do it using tomcat. :-(
You would actually be doing it inside Apache, not inside Tomcat.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.