<outbound-rule> element
Zero or more. This is very similar to a normal rule but it is used for rewriting urls that go through response.encodeURL()
.
Attribute | Possible Value | Explanation |
---|---|---|
enabled (optional) |
true (default) | Enable this rule. |
false | Disable this rule. | |
encodefirst (optional) |
false (default) | Run encodeURL() after running this outbound rule. |
true | Run encodeURL() before running this outbound rule. |
May contain "run", "from", "to" and "set" element(s) also. Example:
<outbound-rule>
<from>^/world.jsp?country=([a-z]+)&city=([a-z]+)$</from>
<to>/world/$1/$2</to>
</outbound-rule>
Using the example above JSP's with the code
<a href="<%= response.encodeURL("/world.jsp?country=usa&city=nyc") %>">nyc</a>
will output
<a href="/world/usa/nyc">nyc</a>
Or JSTL
<a href="<c:url value="/world.jsp?country=${country}&city=${city}" />">nyc</a>
will output
<a href="/world/usa/nyc">nyc</a>
Note, If you are using JSTL (ie, <c:url) this will work also.
URLREWRITE.XML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"
"http://tuckey.org/res/dtds/urlrewrite3.1.dtd">

<urlrewrite use-query-string="true">
<rule>
<from>/show_([0-9]+)_([a-z]+).html</from>
<to>/show.do?id=$1&data=$2</to>
</rule>
<outbound-rule>
<from>/show.do\?id=([0-9]+)&data=([a-z]+)</from>
<to>/show_$1_$2.html</to>
</outbound-rule>

</urlrewrite>

HTML:
urlrewrite將show.do?id=111&data=rewrite自動寫成show_111_rewrite.html,這樣省掉了很多功夫,既有正向,又有逆向。
ExtJS教程- Hibernate教程-Struts2 教程-Lucene教程