users@glassfish.java.net

Re: How to redirect non-www traffic to www

From: <glassfish_at_javadesktop.org>
Date: Tue, 16 Dec 2008 08:58:54 PST

What I did was I created a very simple webapp that redirects to your "real host". Then I created a Virtual Host for each of the "sister sites". Actually, you can have several hosts on a single Virtual Host in GlassFish.

Finally, you deploy the simple WAR against all of those Virtual Hosts (in the GUI, you can choose which 'servers' to deploy to).

Now, mine was bone stupid and simply a Servlet that redirected ANY URL to the host (thus http://myhost.com/newstuff/xyz.jsp was simply redirected to http://www.myhost.com). I stripped the path information (which suited us fine).

You may want to rewrite the URL (this http://myhost.com/newstuff/xyz.jsp become http://www.myjhost.com/newstuff/xyz.jsp). But the principal in the same.

The trick is simply deploy webapps against one or more virtual hosts to perform the work. It's really simple and works great.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=321946