全部博文(2065)
分类: 系统运维
2009-04-16 20:12:02
Note, setting
UrlRewriteFilter
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
confReloadCheckInterval
60
logLevel
DEBUG
statusEnabled
true
statusPath
/status
UrlRewriteFilter
/*
说明一点:logLevel
tolog4j
orcommons
will cause the built in loging to
call either or
as if they were the logging framework,
obviously you will need to have the jar for log4j or commons-logging in your classpath.
可能需要借助于这两个现成的记录日志框架的方法进行相关处理!
3. 简单地解释一下 urlrewrite.xml 文件内容及相关的配置说明The urlrewrite.xml file must have a root element called "urlrewrite" and must contain
PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
"">
^/some/olddir/(.*)$
/very/newdir/$1
其实隐藏在背后的是通过了JAVA中的正则运算实现的。
at least one "rule" element.
1.element
此标签包含的属性
Attribute | Possible Value | Explanation |
---|---|---|
enabled (optional) |
true (default) | Enable this rule. |
false | Disable this rule. |
表示这个规则是将被应用的。否则就不会被应用进来的!
例如:
In the following example requests for /world/usa/nyc
will be transparently forwarded to
/world.jsp?country=usa&city=nyc
^/world/([a-z]+)/([a-z]+)$
/world.jsp?country=$1&city=$2
如果这样进行配置的话那所有传过来的URL
/world/usa/nyc 都会被重定向为
/world.jsp?country=usa&city=nyc
哦!明白了$1、$2表示的是 引用 了标签中的第一个参数与第二个参数。相当于AWK中的接收参数方法
{所以要学习的东西越多那理解起来就越快,这样反而又可以推进自己学习的速度!}
2.
response.encodeURL()
它所包含的相关属性如下:
Attribute | Possible Value | Explanation |
---|---|---|
enabled (optional) |
true (default) | Enable this rule. |
false | Disable this rule. | |
encodefirst (optional) |
true | Run encodeURL() before running this outbound rule. |
false (default) | Run encodeURL() after running this outbound rule. |
3.Using the example above JSP's with the code
^/world.jsp?country=([a-z]+)&city=([a-z]+)$ [源]/world/$1/$2 [替换的URL地址]">nyc
will outputnyc
An element that lets you choose condtions for the rule. Note, all conditions must be met for the rule to be run (unless "next" is set to "or" obvoiusly).
World Rule
Cleanly redirect world requests to JSP,
a country and city must be specified.
^/world/([a-z]+)/([a-z]+)$
/world.jsp?country=$1&city=$2
5.element
Attribute | Possible Value | Explanation |
---|---|---|
type (optional) |
header (default) | If used, the header name must be specified in the "name" attribute. |
method | The method of the request. GET, POST, HEAD etc. | |
port | The port that the web application server is running on. | |
time |
Current time at the server (this will be the number of seconds since 00:00:00 1970-01-01 UTC otherwise known as unix
time).
i.e. (new Date()).getTime()
This can be used for making sure content goes live only at a time you set. | |
year |
Current year at the server.
i.e. (Calendar.getInstance()).get(Calendar.)
| |
month |
Month at the server. January is 0
i.e. (Calendar.getInstance()).get(Calendar.)
| |
dayofmonth |
Day of the month at the server. March first is 1
i.e. (Calendar.getInstance()).get(Calendar.)
| |
dayofweek |
Day of the week at the server. Saturday is 1, Sunday is 7
i.e. (Calendar.getInstance()).get(Calendar.)
| |
ampm |
AM or PM time at the server.
i.e. (Calendar.getInstance()).get(Calendar.)
| |
hourofday |
The hour of the day (24 hour clock) at the server. 10pm is 22
i.e. (Calendar.getInstance()).get(Calendar.)
| |
minute |
The minute field of the current time at the server.
i.e. (Calendar.getInstance()).get(Calendar.)
| |
second |
The second field of the current time at the server.
i.e. (Calendar.getInstance()).get(Calendar.)
| |
millisecond |
The millisecond field of the current time at the server.
i.e. (Calendar.getInstance()).get(Calendar.)
| |
attribute |
Will check the value of a request attribute (don't confuse this with parameter!), name must be set when
using this type.
i.e. request.([name])
| |
auth-type |
Will check the value of a request attribute (don't confuse this with parameter!)
i.e. request.()
| |
character-encoding |
The character encoding of the imcoming request.
i.e. request.()
| |
content-length |
The length of the imcoming request (can be useful if you want to deny large requests).
i.e. request.()
| |
content-type |
The type of the imcoming request. (this is probably not that useful)
i.e. request.()
| |
context-path |
The context path of the imcoming request.
i.e. request.()
| |
cookie |
The value of a cookie, note, name must be specified to use this
i.e. request.()
the find we the one with [name] specified and check the value.
| |
parameter |
A tidier way of checking request parameters than looking for them in the query string. This will check for the
parameter in GET or POST, note, name must be specified.
i.e. request.([name])
| |
path-info |
i.e. request.()
| |
path-translated |
i.e. request.()
| |
protocol | The protocol used to make the request, e.g. HTTP/1.1
i.e. request.()
| |
query-string | The query string used to make the request (if any), e.g. id=2345&name=bob
i.e. request.()
| |
remote-addr | The IP address of the host making the request, e.g. 123.123.123.12
i.e. request.()
| |
remote-host | The host name of the host making the request, e.g. 123qw-dsl.att.com (note,
this will only work if your app server is configured to lookup host names, most aren't).
i.e. request.()
| |
remote-user | The login of the user making this request, if the user has been authenticated, e.g. bobt
i.e. request.()
| |
requested-session-id | Returns the session ID specified by the client, e.g. 2344asd234sada4
i.e. request.()
| |
request-uri | Returns the part of this request's URL from the protocol name up to the query
string in the first line of the HTTP request
i.e. request.
| |
request-url | Reconstructs the URL the client used to make the request. The returned URL
contains a protocol, server name, port number, and server path, but it does not include query string parameters.
i.e. request.
| |
session-attribute |
(note, name must be set)
i.e. session.
| |
session-isnew |
Weather the session is new or not.
i.e. session.
| |
server-name |
The host name of the server to which the request was sent (from the host header not the machine name).
i.e. request.
| |
scheme |
The scheme used for the request, e.g. http or https
i.e. request.
| |
user-in-role |
(Note, the value for this cannot be a regular expression)
i.e. request.
| |
name (optional) |
(can be anything) | If type is header, this specifies the name of the HTTP header used to run the value against. |
next (optional) |
and (default) | The next "rule" and this "rule" must match. |
or | The next "rule" or this "condition" may match. | |
operator (optional) |
equal (default) | Equals. The operator to be used when the condition is run. |
notequal | Not equal to. (i.e. request value != condition value). Note, this operator only work with numeric rule types. | |
greater | Greater than. (i.e. request value > condition value). Note, this operator only work with numeric rule types. | |
less | Less than. (i.e. request value < condition value). Note, this operator only work with numeric rule types. | |
greaterorequal | Greater to or equal to. (i.e. request value >= condition value). Note, this operator only work with numeric rule types. | |
lessorequal | Less than or equal to. (i.e. request value <= condition value). Note, this operator only work with numeric rule types. |
示例:
Mozilla/[1-4] bigboss PROPFIND PUT
6.element
Value can be a regular expression in the Perl5 style [如果懂Perl的话那比较容易理解!]
Attribute | Possible Value | Explanation |
---|---|---|
casesensitive (optional) |
false (default) | This value will be matched using case insentitive match. ie, "/WellingtoN" will match "/wellington". |
true | This value will be matched using case sentitive match. ie, "/aAa" will NOT match "/aaa". |
^/world/([a-z]+)$ 示例!
7.element
Value can be a regular replacement expression in the Perl5 style.
Attribute | Possible Value | Explanation |
---|---|---|
type (optional) |
forward (default) | Requests matching the "conditions" for this "rule", and the URL in the "from" element will be internally
forwarded
to the URL specified in the "to" element. Note: In this case the "to" URL must be in the same context as
UrlRewriteFilter. This is the same as doing:
RequestDispatcher rq = request.getRequestDispatcher([to value]);
|
passthrough | Identical to "forward". | |
redirect | Requests matching the "conditions" and the "from" for this rule will be HTTP redirected.
This is the same a doing:
HttpServletResponse.sendRedirect([to value])) |
|
permanent-redirect | The same as doing:
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
(note, SC_MOVED_TEMPORARILY is HTTP status code 301) |
|
temporary-redirect | The same as doing:
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
(note, SC_MOVED_TEMPORARILY is HTTP status code 302) |
|
last (optional) |
false (default) | The rest of the "rules" will be processed if this one succeeds. |
true | No more "rules" will be processed if this one is a match. | |
encode (optional) |
false (default if under rule) | response.([to]) will be run on the to url before performing the rewrite. |
true (default if under outbound-rule) | response.([to]) will NOT be called. |
/world.jsp?country=$1 示例
8.element
Allows you to set varous(各种) things if the rule is matched.
Attribute | Possible Value | Explanation |
---|---|---|
type (optional) |
request (default) | The same as request.([name],
[value])
(note, name must be set). |
session | The same as request.(true).([name],
[value])
(note, name must be set). |
|
response-header | The same as response.([name],
[value])
(note, name must be set). |
|
cookie | Value can be in the format "[value][:domain[:lifetime[:path]]]". This sets a cookie on the client's browser. The cookie's name is specified by the name attribute. The domain field is the domain of the cookie, such as '.apache.org',the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie (note, name must be set). | |
status | The same as response.([value])
|
|
content-type | The same as response.([value])
|
|
charset | The same as response.([value])
|
|
locale | The same as response.([value])
specify the in the format
(valid
locales are, zh, zh-CN, zh-CN-southern i.e. "-" separating the language, country and variant (if any)).
|
|
name (optional) |
(can be anything) | If type is request, session, response-header, cookie this specifies the name item. |
示例
Mozilla/3\.0 (compatible; AvantGo .*)
.*
AvantGo
UP\.Browser/3.*SC03 .*
.*
Samsung SCH-6100
9.element
Allows you to run a method on an object when a rule and it's conditions are matched.
Attribute | Explanation |
---|---|
class (default) | The class you want to run a method on. Must be a fully qualified name. |
method (optional, default run) | The method you want to run, the method must have the parameters (HttpServletRequest, HttpServletResponse)
e.g. run(HttpServletRequest request, HttpServletResponse response)
Note, if init(ServletConfig) or destroy() is found they will be run at when
creating
or destroying an instance.
|
neweachtime (optional, default false) | If you want new instance of the class to be created before running each time set to true. |
^/world/[a-z]+/[a-z]+$
/world-presentation.jsp
示例: