URL Rewriting with Railo, Tomcat and mod_jk

I am using the very easy Viviotech Railo installer for my Railo installations with Apache and Tomcat on Ubuntu (or CentOS).

By default, this installer uses the mod_jk connector approach to pass requests from Apache to Tomcat (and then to Railo).

I needed to set up some URL rewriting of .cfm files but found that adding rewrite rules to my .htaccess file didn’t work – they were being ignored.

In my case I wanted to rewrite these URLs:

http://www.stannard.net.au/blog/index.cfm/2010/04/29/post-title-here

http://www.stannard.net.au/blog/page.cfm/page-title-here

To these URLs:

http://blog.stannard.net.au/2010/04/29/post-title-here

http://blog.stannard.net.au/page-title-here

I managed to get the URL rewriting working using the following two steps.

1) Add the paths required to Tomcat’s web.xml file

I added the following to my web.xml file

    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>/index.cfm/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>/page.cfm/*</url-pattern>
    </servlet-mapping>

2) Add the rewrite rules to the apache site config file

In Ubuntu, these config files are located in /etc/apache2/sites-available

In my case I added the following lines:

RewriteEngine On
RewriteRule ^/blog/index.cfm/(.*) http://blog.stannard.net.au/$1 [R=301,L]
RewriteRule ^/blog/page.cfm/(.*) http://blog.stannard.net.au/$1 [R=301,L]

The R=301 means moved permanently.
The L means this is the last rule to process.

Note for Viviotech CentOS hosting

If you are hosting with Viviotech on CentOS then you should add these URL rewrite rules to the ‘Extra Tags’ section within the domain administrator of your Kloxo control panel.

This entry was posted in Railo and tagged , , , , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.