How to rewrite / redirect URL’s in Glassfish V3

glassfishrewrite

I'd like to simplify the URL's to access a Glassfish V3 application by removing file extensions and otherwise shortening URL's.

I've already set my application as the default application, so that there is no need to include the context root in the URL.

I'd like to:
* Remove file extensions
* Shorten the URL to files deep in the folder structure

I'd like to do this using pattern matching rather than on a per file basis (Site is small at the moment but will change frequently and grow).

Some examples of what I'd like to do:
* foo.com/bar.html -> foo.com/bar
* foo.com/folder1/folder2/bar2.html -> foo.com/bar2

Any help would be greatly appreciated. Thanks.

Cheers,

Jin

Best Answer

Taken from http://www.sun.com/bigadmin/sundocs/articles/urlrdn.jsp seems like this is what you are looking for.

URL Redirection Within a Domain

You can use the url-prefix element of the redirect_ property to forward a URL to another URL in the same domain.

The following procedure shows how to enable visitors to a web site to type in http://www.mywebsite.com/myproduct1 and be redirected or forwarded to http://www.mywebsite.com/mywarname/products/myproduct1.jsp.

  1. Log in to the Admin Console of Sun Java System Application Server or GlassFish.
  2. In the Admin Console, expand the Configurations node.
  3. Expand the server-config node.

    Ignore this step if you are running a developer domain (a domain that does not have clustering capability).

  4. Expand HTTP Service.

  5. Expand Virtual Servers.
  6. Click server.
  7. On the Edit Virtual Server page, click the Add Property button.
  8. In the Name column, type redirect_1.
  9. If you are using Application Server 9.0, type from=/<context-root>/myproduct1 url-prefix=/mywarname/mypages/products/myproduct1.jsp in the Value column.

    Note - The value of the <context-root> you provide here needs to match the value of the context root specified in the web.xml or application.xml file.

    If you are using Application Server 9.1, type from=/myproduct1 url-prefix=/mywarname/mypages/products/myproduct1.jsp in the Value column.