301 Redirects and Canonicalization in Tomcat 6

Posted on 2009-02-21
Medium Priority
Last Modified: 2013-12-02
Tomcat 6 is acting as both our Application Server as well as our Web Server (that is, we're not using Apache/httpd).

In regular Apache, the global redirection of


can be done using the .htaccess file. Tomcat has no such file.

Does anyone have any ideas as to how non-WWW URLs should be 301 redirected to WWW URLs in Tomcat?

Thank you!

(note, in our implementation, Apache webserver is *not* running so mod_jk and mod_proxy_ajp are unavailable).

*in .htaccess*
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^sampledomain.com [nc]
rewriterule ^(.*)$ http://www.sampledomain.com/$1 [r=301,nc]

Open in new window

Question by:infranco
  • 2
LVL 27

Expert Comment

ID: 23702642
You might be looking for the UrlRewriteFilter http://tuckey.org/urlrewrite/

and the rule in a WEB-INF/urlrewrite.xml might look like
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite
        PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
<condition name="host" operator="equal">^sampledomain\.com</condition>
<to type="redirect">www.sampledomain.com/$1</to>

Open in new window

LVL 27

Accepted Solution

caterham_www earned 2000 total points
ID: 23702647
for a permanental redirect, change
<to type="redirect"> into <to type="permanent-redirect">

Author Comment

ID: 23715814
UrlRewriteFilter looks really interesting. We'll try it out (along with caterham_www's code) and let everyone know how it works out.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question