Skip to content
A Java Web Filter with functionality like Apache's mod_rewrite
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
annotation setup for v5 Nov 30, 2017
container-test remove annotation tests Feb 26, 2019
src Merge pull request #230 from cfmlprojects/modrewrite_tweaks Feb 9, 2019
.gitignore Fix case sensitivity, no substitution, and tabs in rule parsing of mo… May 31, 2018
LICENSE.txt redesigned gzip support Jun 21, 2012
build.xml Fix case sensitivity, no substitution, and tabs in rule parsing of mo… May 31, 2018
pom.xml setup for v5 Nov 30, 2017


UrlRewriteFilter Web Site | Documentation

Based on the popular and very useful mod_rewrite for apache, UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server (such as Resin, Orion or Tomcat), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.

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. can be redirected to
  • A Servlet mapping engine (see Method Invocation)

!UrlRewriteFilter uses an xml file, called urlrewrite.xml (it goes into the WEB-INF directory), for configuration. Most parameters can be Perl5 style Regular Expressions or Wildcard Expressions. This makes it very powerful indeed.

See the manual for more information.

Quick Start

  • Add the following to your WEB-INF/web.xml (add it near the top above your servlet mappings (if you have any)): (see filter parameters for more options)
  • Add urlrewrite.xml into your WEB-INF directory. (src/main/webapp/WEB-INF/ for Maven users)
  • Restart the context.

You can visit (or whatever the address of your local webapp and context) to see output (note: this page is only viewable from localhost).

The best Java IDE IDE Sponsored by JetBrains

Previously on Google Code:

You can’t perform that action at this time.