CFML/ColdFusion · Railo · Server · Tomcat

Tuckey URLRewrite How-To

Today I will walk through how to put into practice use the Tuckey URL Rewrite java web filter under an Apache Tomcat web server.

URL rewriting is the method of converting complex URL parameters into more human readable format to allow more simple and memorable URLs. This can be an important function if you start using frameworks or content management systems which automatically generate long and at times cryptic URLs. While URL rewrite on the more popular Apache HTTP Server is relatively easy to set up using the default mod_rewrite module, reproducing this functionality on Tomcat requires a little more work.

Standard URL:
Rewrite URL:

The GitHub repository of the XML entries used in this article


URLRewrite can be found from one of 2 sources. The official website at the developer’s repository at Google Code

Extracting the downloaded URLRewrite archive reveals a single WEB-INF folder which contains a lib folder and the file urlrewrite.xml. Both these items will need to be copied to the WEB-INF folder of your Tomcat server root directory. For example if was located in /var/www/ or c:\www\ the lib folder and urlrewrite.xml would go in /var/www/ or c:\www\\WEB-INF.

Content of Tuckey URLRewrite 4.0’s archive
Content of WEB-INF with URLRewrite
Content Of A Clean WEB.XML

Generally for most default installations of Tomcat the WEB-INF folder will only contain the single file web.xml. We will need to edit web.xml using a text editor to enable URLRewrite on Tomcat but because it is an XML text file. It can be machined parsed so I’d recommend editing it using a source code text editor such as NotePad++ on Windows or Textmate on OS/X.

Add the following code to web.xml anywhere contained within the <web-app></web-app> tags.

<!-- URL ReWriter -->
    <!-- set the amount of seconds the conf file will be checked for reload
    can be a valid integer (0 denotes check every time,
    empty/not set denotes no reload check) -->
    <!-- you can disable status page if desired
    can be: true, false (default true) -->
Edited WEB.XML

Let’s quickly go through these settings.

confReloadCheckInterval is a numeric value in seconds that tells how frequently URLRewrite should check your urlrewrite.xml rules for any changes. Normally with Tomcat the modification of an XML configuration file requires a restart before the changes are reflected. You can set this value to -1 to disable automatic checking, while our value of 0 will mean that URLRewrite will check the urlrewrite.xml on every HTTP request. It is a great setting while testing and developing but a resource waste if used on a production server.

statusEnabled is a Boolean value that enables a URLRewrite status page that is reachable via a web browser at It is probably best to disable this feature on production servers.

logLevel sets how much logging should be produced by URLRewrite. While the default setting is INFO, I suggest using DEBUG while you are testing. Through in a production environment you will probably want to use ERROR or FATAL to limit logging as URLRewrite can generate some large log files very quickly with more verbose log settings.

statusEnabledOnHosts allows you set which IP addresses and hosts that have access to the URLRewrite status page previously mentioned.

Finally the <filer-mapping> tag tells what kinds of methods to pass through via URLRewrite. The tags <url-pattern></url-pattern> should be left as is to apply URLRewrite to the whole site. While the 2 <dispatcher></dispatcher> tags mean that URLRewrite should be used for all HTTP REQUESTS and HTTP internal FORWARDing.

Once done, save your web.xml file and restart your Tomcat server. If all goes well you should be able to point your browser to and an UrlRewriteFilter 3.2.0 build 1 configuration overview should be shown. Yes that 3.2 version number is incorrectly listed in 4.0. Point your browser to and you should be automatically forwarded to /rewrite-status. When this works then congratulations as you now have URLRewrite enabled on your server. Now I will give you some helpful example rules that may come in use. These rules all go in-between the <urlrewrite></urlrewrite> tags located in the urlrewrite.xml file within the WEB-INF folder. Whenever a page is requested on your Tomcat server the URLRewrite application will in a sequential order process ALL the rules contained in the urlrewrite.xml.

Pretty URL, SES Friendly URL Pass-Through

The most common use of URLRewrite would probably be to enable a 3rd party framework or CMS to use pretty URLs. The rule below is a generic setup that could be adapted for many uses. Generally speaking this should always be the LAST rule listed in your urlrewrite.xml rule set. The rule passes all URL requests to the index.cfm file except requests with URLs pointing to files or folders listed in the <condition></condition> tag regular expression value. So with this rule the URL would be displayed as is in the user’s browser but URLRewrite will actually pass to the Tomcat server. You do want to make sure that the page that contained within the <to></to> tag value is also listed in the (not equal) <condition></condition> value otherwise you could run into an infinite loop.

<rule enabled="true">
    <name>Generic Pretty URLs Pass-through</name>
    <condition type="request-uri" operator="notequal">^/(index.cfm|robots.txt|osd.xml|flex2gateway|cfide|cfformgateway|railo-context|admin-context|files|images|jrunscripts|javascripts|miscellaneous|stylesheets)</condition>
    <to type="passthrough">/index.cfm/$1</to>

Permanent Redirection

This rule is specifically for when you want to do a permanent redirection using the HTTP code 301. If we break this rule down, the <rule enable=""> Boolean enables you to selectively turn off this rule without the need to comment it out. The <name></name> tags contains the label you wish to use to describe the rule. <from></from> tag contains a regular expression to forward all requests for the documents.cfm page plus any URL parameters. While <to></to> is the new URL to redirect to. The attribute type tells URLRewrite to send a permanent direct code to the browser requesting the URL, while the attribute last = true tells URLRewrite not to process any further rules for this page request.

<rule enabled="true">
    <name>Permanent redirect example</name>
    <to type="permanent-redirect" last="true">/file/list/document</to>

Selective HTTPS Enforcement

If you have HTTPS setup on your server you can use URLRewrite to enforce certain folders, URL paths or files to only be served on an encrypted HTTPS protocol. The <condition></condition> tag is used to enforce additional policies as to when the rule should be implemented. The attribute type with a value of scheme and the attribute operator with a value of equal states that when the URL scheme (http, https, ftp, etc) is equal to HTTP then apply this rule.

<rule enabled="false">
    <name>Force HTTPS example</name>
    <note>Automatically redirects adminstration requests to a secure protocol.</note>
    <condition type="scheme" operator="equal">^http$</condition>
    <to type="permanent-redirect" last="true">$1</to>

Railo HTTPS Enforcement railo-content.

<rule enabled="false">
    <name>Force HTTPS example</name>
    <note>Automatically redirects adminstration requests to a secure protocol.</note>
    <condition type="scheme" operator="equal">^http$</condition>
    <to type="permanent-redirect" last="true">$1.cfm</to>

Conditions Based On URL Parameters

You can also apply conditions to user supplied URL parameters. In the example below the condition looks for the URL parameter named fruit and sees if its value is either kiwi, apple or orange. If the values match then it redirects to a replacement URL which also incorporates the parameter. The URL request would forward to

<rule enabled="true">
    <name>Selective fruit example redirect</name>
    <condition type="parameter" name="fruit" operator="equal">(apple|kiwi|orange)</condition>
    <to type="permanent-redirect" last="true">list/fruit/%{parameter:fruit}</to>

Extra Help

39 thoughts on “Tuckey URLRewrite How-To

  1. Thanks Ben. It still seem to be a problem. I get the below error:
    The page isn’t redirecting properly

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

    My web.xml








    My urlrewrite.xml

    Remove trailing slash

    When I run against:

    it always tries rewrites to:

    and fails with the error “The page isn’t redirecting properly”.

    My problem is whenever I request the “”, the dispatcher servlet is sending code 302 and redirecting with an extra “/”. I’m trying to solve it using the tuckey.

    Your quick help is much appreciated.

    1. Hi Guruprased,

      Unfortunately I can’t really help you as you cannot post code in the WordPress comments. Also I run a blog but I am not an expert with Tuckey. Your issue could be a simple server or a web application configuration issue and using Tuckey maybe an overkill solution or lead you to an endless redirection loop.

      But if you think Tuckey is your only solution. Can I suggest subscribing to and asking there?
      Use this question as a template for your own and most importantly use the same tags, ie java, regex, url-rewriting, tuckey-urlrewrite-filter.

  2. Hi,

    It is a wonderful feature. Thanks for creating this.

    I’ve a specific requirement. Can you please help.

    I want to redirect the below two things:



    Any quickhelp on this is much appreciated. I just need the regular expression for tag and tag. I’ve got the rest of the setup. The “domain” can change based on the environment we deploy.


    1. Hi Guruprasad,

      I have not tested these but Google suggests.

      Your from regex: ^(.*)\/(\?.*)?$
      Your to regex: $1$2

      Best of luck.

    1. There is no need to use Tuckey to redirect domain names. You could just set-up the domain name service provider of to automatically redirect all requests to This is usually either called domain name forwarding or redirection.

    1. Hi Ben,
      My Url doesn’t have a % sign. The code that I had pasted in the above comment wasn’t displayed properly.
      I posted the same in a stackoverflow question.

      The URL Rewrite Filter is not accepting a paramter named “_escsaped_fragment_” that means no special characters.
      Please see the question in the stackoverflow link and help me please.
      I even started a bounty there.

  3. Hi Ben,
    Referring to Conditions Based On URL Parameters,
    I’ve done something using UrlRewriteFilter which is actually required to make my site Google crawl-able.
    Here’s how it goes.


    It fails throwing java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern – %%7.
    As my variable contains underscores (_escaped_fragment_), where in it works fine with a parameter variable called ‘friuit’.
    Please help me get out of it.

  4. Hi Ben,
    I’m using eclipse configured with Tomcat 7.
    I can browse to: http://localhost:8090/fg/rewrite-status and see the rules.

    I use the default rule to test if it works:

    The rule means that requests to /test/status/ will be redirected to
    the url will be rewritten.


    But it seems like there is no redirect/rewrite when I’m browsing to: http://localhost:8090/fg/test/status or http://localhost:8090/test/status.

    I’m getting HTTP error 404.

    Thanks in advance.

  5. Hi Ben,

    I’m using Tomcat 6 and I have to do this on my project:

    etc, etc… Every user will have their own subdomain.
    Is it possible to achieve using urlrewrite?

    Thanks! 🙂

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s