How to direct different URLs to different pages in Same Tomcat App
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 v开发者_如何学JAVAirtual hosting in tomcat? Or can it be simply done using my domain name hosting providers settings?
Thanks in advance.
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.
精彩评论