Urlrewritefilter 4.0.3Home download GitHub items StackOverflow Search Urlrewrite StackOverflow
Background License Update log
ConfigurationInstallation hint filter parameter profile ant task Mod_rewrite Style Annotation example method call URL abstract mod_rewrite vs urlrewritefilter extension Urlrewritefilter
Handbook
Community support is available on Urlrewrite StackOverflow.
Read the examples used and a sample ant task report. If you have any suggestions/examples of this manual please refer to the group. Install Add the following maven dependencies or add urlrewritefilter-4.0.3. jar directly into your web-inf/lib directory.
<dependency>
<groupId>org.tuckey</groupId>
<artifactid>urlrewritefilter</ artifactid>
<version>
4.0.3
</version>
</dependency>
Add the following to your Web-inf/. XML (add top around your servlet map (if you have one):(see more options for filter parameters)<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class> org.tuckey.web.filters.urlrewrite.urlrewritefilter</filter-class>
</filter>
< filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</ url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>forward</dispatcher >
</filter-mapping>Add urlrewrite.xml to your Web-inf directory. (Src/main/webapp/web-inf/maven user) to restart the context.
You can access the http://127.0.0.1:8080 rewrite-status (or other local application and context address) to see the output (Note: This page can only be from localhost). Filter Parameters
There are some advanced filtering parameters to enable the configuration file reload and so there is self-evident.
<filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class> Org.tuckey.web.filters.urlrewrite.urlrewritefilter</filter-class> <!--Set the amount of seconds the Conf fi Le'll be checked for reload can is a valid integer (0 denotes check every time,-1 denotes no reload check, DEFA ult-1)--> <init-param> <param-name>Confreloadcheckinterval</param-name> <param-value>60</param-value> </init-param> <!--if need to The conf file path can be changed it are specified as a path relative to the root of your context (Default/web-inf /urlrewrite.xml)--> <init-param> <param-name>Confpath</param-name> <param-value>/WEB-INF/urlrewrite.xml</param-value> </init-param> &L t;!
--Sets up log level (would be logged to the context log) can be:slf4j, TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL, Sysout:{level} (ie, sysout:debug) If you are have trouble using normal levels use Sysout:debug (default WARN )--> <init-param> <param-name>loglevel</param-name> <param-value>DEBUG</param-value> </init-param> <!--you can Chan GE status Path so this it does not conflict with your installed apps (note, defaults to/rewrite-status) Note, mus T-start with/--> <init-param> <param-name>Statuspath</param-name> <param-value>/status</param-value> </init-param> <!--you can di Sable Status page If desired can be:true, False (default true)--> <init-param> <PARAM-NAME&G Tstatusenabled</param-name> <param-value>true</param-value> </init-param> <!--you want To allow the the Status page statusenabledonhosts are a comma delimited list of hosts, * Can be u Sed as a wildcard (defaults to "localhost, local, 127.0.0.1")--> <init-param> <param-name>statusenabledonhosts</param-name> <param-value>localhost, dev.*.myco.com, *.uat.mycom.com</param-value> </ini T-param> <!--you could want to allow more hosts to look at the status page statusenabledonhosts is a comma D elimited List of hosts, * can be used as a wildcard (defaults to "localhost, local, 127.0.0.1")--> <init-pa Ram> <param-name>statusenabledonhosts</param-name> <param-value>localhost, dev.*.myco.com, *.uat.mycom.com</param-value> </ini T-param> <!--defaults to False. Use mod_rewrite style configuration file (if it is true and Confpath are not specified Confpath'll be set to/web-i nf/.htaccess)--> <init-param> <param-name>modrewriteconf</param-name> <param-value>false</param-value> </init-param> <!--load Mod_rew
Rite style configuration from this parameter ' s value.
Note, Setting This parameter would mean that all other conf parameters are ignored. <init-param> <param-name>Modrewriteconftext</param-name> <param-value> rewriterule ^/~ ([^/]+)/? (. *)/u/$1/$2 [R] Rewriterule ^/([Uge])/([^/]+) $/$1/$2/[R] </param-value> < /init-param>--> <!--defaults to False. Allow conf file to is set by calling/rewrite-status/?conf=/web-inf/urlrewrite2.xml designed to is used for TE Sting only <init-param> <param-name>allowconfswapviahttp</param-name> <param-value>false</param-value> </init-param>--> </ filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <URL-PATTERN>/*&L T;/url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> < /filter-mapping>
Note that setting LogLevel to SLF4J will cause the built-in log to be invoked slf4j if it is a log frame, it is obvious that you need the jar slf4j in your classpath. configuration file Web-inf/urlrewrite.xml
< Urlrewrite > < regulation > < Outbound-rule > < class rule > < name > < note > < condition > From > < <,> < set > < run > Returns the reference variable feature |
The configuration is through a simple XML file in your life-INF folder. It should be called Urlrewrite.xml. It may be useful to read the Urlrewritefilter DTD (document type definition). Also make sure you take a look at the example. The appearance of a simple configuration file:
<?xml version= "1.0" encoding= "Utf-8"?> <!
DOCTYPE urlrewrite public
"-//tuckey.org//dtd urlrewrite 4.0//en"
"http://www.tuckey.org/res/dtds/ Urlrewrite4.0.dtd ">
<urlrewrite>
<rule>
<from>^/some/olddir/(. *) $</from >
<to type= "redirect" >/very/newdir/$1</to>
</rule>
<rule match-type= " Wildcard ">
<from>/blog/archive/**</from>
<to type=" redirect ">/roller/history/$1 </to>
</rule>
</urlrewrite>
Urlrewrite. The XML file must have a root element called "Urlrewrite" and must contain at least one element "rule".
A rule must contain a "from" and "Come" and can have 0 or more condition elements and 0 or more and/or "sets" elements.
When a "rule" is processed on an incoming request, all the "conditional" elements must be met, and then "from" will be applied to the generated URL request URL and the final application, "from" mode. As long as the rules match, the settings will run.
When executing a rule filter (very simple) will traverse each of the rules to do and launch such pseudocode:
Pattern.compile (<from> element);
Pattern.matcher (request URL);
Matcher.replaceall (<to> element);
if (<condition> elements match && matcher.find ()) {
handle <set> elements (if any)
Execute & Lt;run> elements (if any)
perform <to> element (if any)
}
< urlrewrite > elements The top-level element.
| Property |
Possible values |
explain |
Default-match-type (optional) |
Regular Expressions Default |
All rules and their conditions will be processed (unless a rule is specified using the Java regular expression engine balance). |
| Wildcard characters |
All rules and their conditions will be machined using the wildcard expression engine (unless the balance specifies a rule). |
When decoding (optional) |
Head, UTF8 Default |
When the URL decodes request.getcharacterencoding () will be used, if the null will be used utf-8. |
| Zero |
Do not decode. (Note that this means 0 when the literal string is decoded = "0") |
| Head |
Use only request.getcharacterencoding () decoding. |
| Coding |
Use only one specific character encoding, such as iso-8859-1. See the character encoding for the Java character set object. |
| Head, (coded) |
When the URL decodes request.getcharacterencoding () will be used if it is empty for a particular character encoding such as iso-8859-1. See the character encoding for the Java character set object. |
Use-query-string (optional) |
Fake Default |
The query string will not be appended to the URL element and "from." |
| The real |
The match to the URL query string is appended to the FROM element. |
Use environment (optional) |
Fake Default |
The context path will not be added to the URL that matches the from element. |
| The real |
The URL path for the context will be added to the "from" element. |
< rules > elements0 or more. The basis of a rule.
| Property |
Possible values |
explain |
Enable (optional) |
the real Default |
Enable the rule. |
| False |
Disables this rule. |
Balanced type (optional) |
Regular Expressions Default |
The condition of this rule will be handled using the Java regular expression engine. |
| Wildcard characters |
This rule will be processed using the conditional wildcard expression engine. |
The following sample request/World/US/New York will be transparently forwarded/world.jsp
<rule match-type= "regex" >
<from>^/world/([a-z]+)/([a-z]+) $</from>
<to>/ World.jsp</to>
</rule>
<rule match-type= "Wildcard" >
<from>/world/*/*</from>
<to>/world.jsp</to >
</rule>
< outbound-rule > elements 0 or more. This is very similar to a normal rule, but is used to override the URL Response.encodeurl ().
| Property |
Possible values |
explain |
Enable (optional) |
the real Default |
Enable the rule. |
| False |
Disables this rule. |
Encodefirst (optional) |
Fake Default |
Run the outbound rule after running Encodeurl (). |
| The real |
Run this outbound rule before running Encodeurl (). |
May contain "run", "from", "Pair" and "set" elements (s). Example:
<outbound-rule>
<from>^/world.jsp?country= ([a-z]+) &city= ([a-z]+) $</from>
<to>/world/$1/$2</to>
</outbound-rule>
Using the code from the example JSP above
< a href = "<% = Response.encodeurl ("/world.jsp? country = usa& City = New York ") New York% >" > </>
The output
< a href = "/World/USA/New York" > New York </>
or Jstl
< a href = "< C:url value ="/world.jsp? Countries and cities of country = $ {} = $ {} City "New York/>" > </>
The output
< a href = "/World/USA/New York" > New York </>
Please note that if you are using Jstl (i.e. < C:url) this will work. < name > elements
An optional element is used to record the name of the rule. This can use the rules, Outbound-rule. See