This redirects or rewrites URLs based on a regular expression. It tests the requested
URLs against a regular expression. If it finds a match it then uses the substiution
expression to rewrite a new URL. For a description of the regular expression language see
See Also: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html . This handler
operates in two modes either using external redirects (i.e. 302 HTTP code), or internal
redirects. The new URL expression can reference groups in the regular expression using
${<group number>}. Substitution expressions can also reference configuration
properties by using the notation. For example, ${http.port} would return the port of
the pygmy server.
Here is an example of a URL rule and substition expression for creating a URL to user's
home directories. Remember to escape "e;\"e; character in your properties files
otherwise your expression will not work. To help you debug these problems this Handler
will log a message at the debug level so you can see what the regular expression has been
set to.
aRedirect.class=pygmy.handlers.RedirectHandler
aRedirect.rule=/~(\\w+)
aRedirect.subst=/home/${1}/public_html
The new URL built from the subst expression by default will be sent back to the client
in a 302 HTTP status code. But, there are cases when you don't want to expose the
rewritten URL to the outside world. This handler can internally redirect so that the
new URL won't be sent back to the client. In our example above we might want to keep
the URL to the user's directory private. Using internal redirects the browser won't see
the new URL containing: /home/chuck/public_html. It could be a serious security hole if
someone is allowed to request /home/chuck!
RedirectHandler only responds to non-internal requests. This handler will not
redirect or rewrite interal requests. This is so redirects don't get into an
infinite loop when processing. Something to look out for when using external redirects.
Most clients fail if they are redirected too many times.
rule | The regular expression rule to use for matching on the requested URL. | None | Yes |
subst | The string to use for rewriting a new URL that will be used in another request. | None | Yes |
useInternal | Indicates the new URL will be internally redirected.
If it is true, then the new URL will be used internally redirected.
If false, then the new URL will be sent back to the client with the HTTP code specified by redirectCode. | false | No |
redirectCode | This defines the HTTP code that will be sent back when we substitue or rewrite a URL. | 302 | No, but ignored if useInternal is true. |
|