Rewrite-dispatch
From Resin 3.0
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Configuration]] | [[Category:Configuration]] | ||
− | + | Resin's <rewrite-dispatch> directive rewrites and dispatches rules similar to the Apache mod_rewrite module. It can appear in the <[[host]]> or the <[[web-app]]> directives. | |
− | == Redirecting a URL == | + | == Overview == |
+ | |||
+ | The <rewrite-dispatch> directive tries each sub-directive in order for a [[regular expression]] match. The first matching directive redirects the request. | ||
+ | |||
+ | <rewrite-dispatch> may occur in a <[[host]]> or in a <[[web-app]]>. | ||
+ | |||
+ | Starting with Resin 3.0.19, <rewrite-dispatch> may also occur in the <[[server]]> block. The regexp in that case will be the entire URL, not just the path portion. | ||
+ | |||
+ | === Escaping === | ||
+ | |||
+ | Since the rewrite rules are written in Resin's XML configuration files, XML escaping rules apply. In particular a & character must be escaped with &amp; | ||
+ | |||
+ | == 302 Redirecting a URL == | ||
To redirect a URL with a HTTP 302 redirect use: | To redirect a URL with a HTTP 302 redirect use: | ||
Line 10: | Line 22: | ||
<redirect regexp='^/foo' target='/bar'/> | <redirect regexp='^/foo' target='/bar'/> | ||
</rewrite-dispatch> | </rewrite-dispatch> | ||
+ | |||
+ | == 301 Permanently Move a URL == | ||
+ | |||
+ | To redirect a URL with a HTTP 301 moved-permanently use: | ||
+ | |||
+ | <rewrite-dispatch> | ||
+ | <moved-permanently regexp='^/foo' target='/bar'/> | ||
+ | </rewrite-dispatch> | ||
+ | |||
+ | (requires Resin 3.0.18) | ||
== Forwarding a URL == | == Forwarding a URL == |
Latest revision as of 08:55, 14 January 2009
Resin's <rewrite-dispatch> directive rewrites and dispatches rules similar to the Apache mod_rewrite module. It can appear in the <host> or the <web-app> directives.
Contents |
Overview
The <rewrite-dispatch> directive tries each sub-directive in order for a regular expression match. The first matching directive redirects the request.
<rewrite-dispatch> may occur in a <host> or in a <web-app>.
Starting with Resin 3.0.19, <rewrite-dispatch> may also occur in the <server> block. The regexp in that case will be the entire URL, not just the path portion.
Escaping
Since the rewrite rules are written in Resin's XML configuration files, XML escaping rules apply. In particular a & character must be escaped with &
302 Redirecting a URL
To redirect a URL with a HTTP 302 redirect use:
<rewrite-dispatch> <redirect regexp='^/foo' target='/bar'/> </rewrite-dispatch>
301 Permanently Move a URL
To redirect a URL with a HTTP 301 moved-permanently use:
<rewrite-dispatch> <moved-permanently regexp='^/foo' target='/bar'/> </rewrite-dispatch>
(requires Resin 3.0.18)
Forwarding a URL
To internally forward a URL to a target using the Servlet forward() call use:
<rewrite-dispatch> <forward regexp='^/foo' target='/bar'/> </rewrite-dispatch>
403 Forbidden
To send a HTTP 403 forbidden message for a URL, use:
<rewrite-dispatch> <forbidden regexp="^/foo"/> </rewrite-dispatch>
404 Not Found
To send a HTTP 404 Not Found message for a URL, use:
<rewrite-dispatch> <not-found regexp="^/foo"/> </rewrite-dispatch>
410 Gone
To send a HTTP 410 Gone message for a URL, use:
<rewrite-dispatch> <gone regexp="^/foo"/> </rewrite-dispatch>