Reprint: Click to open link
The element analysis configuration file in the Urlrewrite.xml configuration file is a simple XML file that is placed under the Web-inf folder named Urlrewrite.xml name, Urlrewritefilter DTD The file is very effective for learning and understanding the profile. You can download the latest DTD (http://tuckey.org/urlrewrite/manual/3.0/index.html) on the official website (due to the limited English level, the official website is English, please understand ) 1, Urlrewrite.xml has a root element Urlrewrite, and contains at least one matching rule, Rule 2, a rule element must contain a from element and a to element, but condition element and set element can not, There can also be more than 3, when a rule element intercepts a request, all the condition elements are satisfied. This will only match the From,
Optional: Optional
<urlrewrite> elements: top-level elements: the attribute values inside are optional
Attribute |
Possible Value |
explanation |
Default-match-type (optional) |
Regex (default) |
When using regular expressions, all rule and conditions will be examined (unless match-type specifies a specific value in rule) |
Wildcard |
When wildcard characters are used, all rule and conditions are reviewed (unless match-type specifies a specific value in rule) |
Decode-using (optional) |
UTF8 (default) |
Code used for encoding: Utf-8 |
Null |
Do not specify encoding |
[Encoding] |
Specify a supported encoding for example: ISO-8859-1,GBK. |
Use-query-string (optional) |
False (Default) |
The query string is not appended to the matching from element |
True |
The query string will be appended to the matching from element |
Use-context (optional) |
False (Default) |
The application path is not appended to the matching from element |
True |
The application path will be appended to the matching from element |
<rule> Element (Zero or more. The basis of a rule.):
Attribute |
Possible Value |
explanation |
Enabled (optional) |
True (default) |
Enable this rule |
False |
Disable this rule. |
Match-type (optional) |
Regex (default) |
This rules and its conditions will be reviewed by regular expressions. |
Wildcard |
This rules and its conditions will be reviewed by wildcard characters. |
Regular Expressions:
<rule match-type= "regex" >
<from>^/world/([a-z]+)/([a-z]+] $</from>
<to>/ World.jsp</to>
</rule>
Wildcard characters:
<rule match-type= "Wildcard" >
<from>/world/*/*</from>
<to>/world.jsp</to>
</rule>
<outbound-rule> Element (zero or more):This is similar to the normal rule, except that it is used to rewrite the URL requested by using Response.encodeurl ().
Attribute |
Possible Value |
explanation |
Enabled (optional) |
True (default) |
Enable this rule |
False |
Disable this rule. |
Encodefirst (optional) |
False (Default) |
Execute Encodeurl after Outbound-rule execution () |
True |
Execute Encodeurl () before executing outbound-rule |
<outbound-rule>
<from>^/world.jsp?country= ([a-z]+) &city= ([a-z]+) $</from>
<to>/world/$1/$2</to>
</outbound-rule>
Use the rules above to execute the following code: <a href= "<%= response.encodeurl ("/world.jsp?country=usa&city=nyc ")%>" >nyc</ A>
Will output: <a href= "/world/usa/nyc" >nyc</a> or use:
<a href= "<c:url value="/world.jsp?country=${country}&city=${city} "/>" >nyc</a> also output <a href= "/world/usa/nyc" >nyc</a>
<name> elements:This is an optional parameter that defines the name of the rule and can also be used for Outbound-rule
<rule>
<name>world rule</name>
<from>^/world/([a-z]+)/([a-z]+] $</from>
<to>/world.jsp?country=$1&city=$2</to>
</rule>
<note> elements:A simple optional parameter that explains the rule and outbound-rule description
<rule>
<name>world rule</name>
<note>
cleanly redirect World requests to JSP,
a country and city must is specified.
</note>
<from>^/world/([a-z]+)/([a-z]+) $</from>
<to>/world.jsp</to>
</rule>
<condition> elements:An element that sets conditions for rule, and all conditions are executed when rule is intercepted (unless next is set to or)
Attribute |
Possible Value |
explanation |
Type (optional) |
Header (default) |
If you use this, the header name must be named the property value of "name" |
Method |
Method of request GET, POST, head, etc. |
Port |
Port that the application server is running on |