users@glassfish.java.net

Global Redirects and default-web.xml

From: <glassfish_at_javadesktop.org>
Date: Fri, 19 Feb 2010 14:24:47 PST

Hi,

I'm trying to do something which would seem rather simple and a common use case but I cannot find a good solution for this in Glassfish (v2.1).

My scenario is simple. I want to redirect anyone coming into my site with just the domain, to be redirected to a full host name. e.g.:

  http://domain.com -> http://www.domain.com

and also anyone coming into the site with another domain (because of 'legacy' domain names) being redirected to the my primary host name. e.g.:

  http://olddomain.com -> http://www.domain.com
  http://www.olddomain.com -> http://www.domain.com

The main issue is that I want to do this for *all* possible urls on the site, no matter what the URL path and query parameters might be. e.g.:

http://domain.com/foo/bar/mypage.jsp?id=5 -> http://www.domain.com/foo/bar/mypage.jsp?id=5
etc.

I've tried what's described here:

  http://www.sun.com/bigadmin/sundocs/articles/urlrdn.jsp

But the redirect only happens for the exact matches. So the base root URL is redirected but not anything below it. We have many points of entry into the site and links to specific pages via search engines, etc. and need a global solution.

I can rather easily do this in code as a filter, but the filter is web app specific. I've also seen this: http://tuckey.org/urlrewrite/ but again this would be web app context specific.

I've been thinking about maybe trying to put a filter in default-web.xml but this seems to be loaded by each web app and I'm not sure how well that would behave...

So my questions are:

1. Is there any out of the box way to do this? I would think there is a general handler in the Application Server which routes requests to each web application so it would be great if there was a way to bolt into it to handle this.

2. If there isn't an out of the box solution, would putting the UrlRewrite filter, or my own custom filter, in default-web.xml be recommended? It seems like having this load up with each web app in the application server is not great.

BTW, front ending this with Apache and mod_rewrite is not an option for this scenario. Basically what I need is a mod_rewrite for Grizzly or something of the sort.

Thanks,

Andrea
[Message sent by forum member 'arosso' (arosso_at_esri.com)]

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