tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: AW: AW: Permanent Redirect?
Date Thu, 30 Apr 2009 19:50:34 GMT
Hash: SHA1


On 4/30/2009 8:33 AM, André Warnier wrote:
> At the risk of stating the obvious :
> There are two different types of redirect :
> - an "internal redirect" consists of just modifying the request URL, and
> recycling the request internally from the beginning.

This is actually called a "forward", and is often confused with a
"redirect" by lots of people. The request is /not/ "recycled" or even
started-over. It is actually re-delegated (if such a term exists). If
you write a filter that performs 5 forwards and then throws an
exception, you'll see a stack trace that looks something like this:

java.lang.Exception: Intentionally-thrown exception
at my.Filter.doFilter
at RequestDispatcher.forward
at my.Filter.doFilter
at RequestDispatcher.forward
at my.Filter.doFilter
at RequestDispatcher.forward
at my.Filter.doFilter
at RequestDispatcher.forward
at my.Filter.doFilter

Forwarding a request is actually a method call, not a reset of the
request. This is important to understand because it has certain
implications on the nature of the request and response objects. For one,
it means you can /wrap/ a request and/or response with some other object
in order to alter the behavior of the resources targeted with the forward.

> - an "external redirect" means that the server sends a 301/302 HTTP
> response to the browser, telling it (in another HTTP header) "and here
> is the URL that you should try instead".
> (in that case it is a complete URL, http://hostname included)

This is really the only operation actually called "redirect".

> Just to make sure that you read the documentation of URLrewriteFilter
> properly, and did not miss something. Maybe they are named differently
> in the documentation ?

Of course urlrewrite provides a way to redirect.

Specifically, you set 'type="redirect"' which results in the filter
executing a HttpServletResponse.sendRedirect(). Even better, the OP
should use type="permanent-redirect" as it will sent a 301 response.

Technically speaking, a redirect should have a complete URL (including
protocol) in it, but the example shown in the user manual lacks it:

           <to type="redirect">/very/newdir/$1</to>

To do a redirect to another site, just fully-qualify the URL:

           <to type="redirect">$1</to>

Honestly, I haven't actually /tried/ this, but the documentation
suggests that it will work. I would have tried this technique before
posting back to the list (or asking a question on the surely-helpful
user group for urlrewrite:

- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message