UrlRewriteFilter Logo
UrlRewriteFilter

A Java Web Filter for any compliant web application servers (such as Tomcat, JBoss, Jetty or Resin), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.

Install


1

Add urlrewritefilter-5.1.3.jar
to WEB-INF/lib

Or add Maven dependency
<dependency>
    <groupId>org.tuckey</groupId>
    <artifactId>urlrewritefilter</artifactId>
    <version>5.1.3</version>
</dependency>

2

To WEB-INF/web.xml add (near the top above any servlet mappings): (see filter parameters for more options)
<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

3

Add urlrewrite.xml in WEB-INF (src/main/webapp/WEB-INF/ for Maven users)

After restarting you can visit http://127.0.0.1:8080/rewrite-status (or whatever the address of your local webapp and context) to see output (note: this page is only viewable from localhost).

Documentation

What is URL Rewriting?

URL rewriting is very common with Apache Web Server (see mod_rewrite's rewriting guide) but has not been possible in most java web application servers. The main things it is used for are:

  • URL Tidyness / URL Abstraction - keep URLs tidy irrespective of the underlying technology or framework (JSP, Servlet, Struts etc).
  • Browser Detection - Allows you to rewrite URLs based on request HTTP headers (such as user-agent or charset).
  • Date based rewriting - Allows you to forward or redirect to other URL's based on the date/time (good for planned outages).
  • Moved content - enable a graceful move of content or even a change in CMS.
  • Tiny/Friendly URL's (i.e. blah.com/latest can be redirected to blah.com/download/ver1.2.46.2/setup.exe)
  • A Servlet mapping engine (see Method Invocation)

4.0 User Manual

5.1 User Manual


Articles

This filter has been mentioned at:

Support

Source