301 Redirects and Canonicalization in Tomcat 6

Posted on 2009-02-21
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} ^ [nc]

rewriterule ^(.*)$$1 [r=301,nc]

Open in new window

Question by:infranco
    LVL 27

    Expert Comment

    You might be looking for the UrlRewriteFilter

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

    Open in new window

    LVL 27

    Accepted Solution

    for a permanental redirect, change
    <to type="redirect"> into <to type="permanent-redirect">

    Author Comment

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    A step by step SEO guide to creating content that drives traffic and maximizes page views by using the right tricks, tools and keyword analysis. You are the subject matter expert.   You have forgotten more about your area of expertise than most …
    [Part 6 of a 6 part series called SEO Basics: 5 SEO Secrets for Creating Content that Drives Traffic (…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now