How do I install URL Rewrite Filter for Tomcat?

1,898 views
Skip to first unread message

Dr James Bayley

unread,
Jan 26, 2011, 7:02:47 AM1/26/11
to Railo
I am building a new application. Presently I plan to have the standard
distribution of Railo on Tomcat deployed to Amazon's Elastic
Beanstalk. (Thanks Mark for your recent post).

To keep things simple I will use Tomcat's own webserver. I will have
ReSTful resources and will need to use URL rewriting. The preferred
tool for this is http://www.tuckey.org/urlrewrite/

I have downloaded this and the first instructions are

<quote from manual>
----------------------------------------------------
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)


<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>
</filter-mapping>
--------------------------------------------------------------
</quote from manual>

Unfortunately my standard distribution of Railo on Tomcat does not
have a WEB-INF/web.xml file!

Can someone please advise me how to install this filter.

Many thanks
James

Aaron Greenlee

unread,
Jan 26, 2011, 8:42:55 AM1/26/11
to ra...@googlegroups.com
Here, use mine:

<?xml version="1.0" encoding="ISO-8859-1"?>
   version="2.5">

  <display-name>Your App</display-name>
  <description>
     About your app
  </description>

<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>
</filter-mapping>
</web-app>

Aaron Greenlee

unread,
Jan 26, 2011, 8:46:37 AM1/26/11
to ra...@googlegroups.com
And, if it helps, here are my rewrite rules for SES that support my ColdBox application on my development box.

Simple rule explanation:
If the file requested does not end with an extention such as PHP or JPG AND the path does not start with something like "CDN" or "test" , the request is rewritten to "/index.cfm/{path_requested}"

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
 <!--
 
    Configuration file for UrlRewriteFilter
 
-->
<urlrewrite>
<rule>
<note>
Enable TomCat to have SES links.
</note>
<condition type="request-uri" operator="notequal">\.(bmp|gif|jpe?g|png|css|js|txt|pdf|doc|xls|xml|cfc|ico|php|asp)$</condition>
<from>^/(?!cdn|src|railo-context|test|mxunit|remote)(.*)$</from>
<to>/index.cfm/$1</to>
</rule>
</urlrewrite>

Dr James Bayley

unread,
Jan 26, 2011, 11:26:57 AM1/26/11
to Railo
Brilliant! This worked first time. Many thanks. I will now move on to
the pattern matching bit in your next post.

On Jan 26, 1:42 pm, Aaron Greenlee <aarongreen...@gmail.com> wrote:
> Here, use mine:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

Dr James Bayley

unread,
Jan 26, 2011, 11:49:57 AM1/26/11
to Railo
The example above was helpful to demonstrate rewriting by filetype
which I will need later. My immediate requirement was to impelment
ReST resources.

The simple rule:

<rule>
<note>
Enable TomCat service requests for ReST resources
</note>

<from>/test/rewriter/([0-9]+)</from>
<to>/test/rewriter/userid.cfm?userid=$1</to>
</rule>

allows the brower to request a URL that contains a userid and have it
redirected to a script that accept the userid as a parameter. So for
example

/12345
/347684
/4879245

are all processed by userid.cfm

All my problems are solved. Thanks for your help Aaron.
James


On Jan 26, 1:46 pm, Aaron Greenlee <aarongreen...@gmail.com> wrote:
> And, if it helps, here are my rewrite rules for SES that support my ColdBox
> application on my development box.
>
> *Simple rule explanation:*
Reply all
Reply to author
Forward
0 new messages