📄 modrewriteconfloader.java
字号:
*/
if ("forbidden".equalsIgnoreCase(flag) || "F".equalsIgnoreCase(flag)) {
SetAttribute set = new SetAttribute();
set.setType("status");
set.setValue("403");
rule.addSetAttribute(set);
}
/*
# 'gone|G' (force URL to be gone)
This forces the current URL to be gone - it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.
*/
if ("gone".equalsIgnoreCase(flag) || "G".equalsIgnoreCase(flag)) {
SetAttribute set = new SetAttribute();
set.setType("status");
set.setValue("410");
rule.addSetAttribute(set);
}
/*
# 'last|L' (last rule)
Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.
*/
if ("last".equalsIgnoreCase(flag) || "L".equalsIgnoreCase(flag)) {
rule.setToLast("true");
}
/*
# 'next|N' (next round)
Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop.
Be careful not to create an infinite loop!
*/
if ("next".equalsIgnoreCase(flag) || "N".equalsIgnoreCase(flag)) {
log.info("next flag [N] not supported");
}
/*
# 'nocase|NC' (no case)
This makes the Pattern case-insensitive, ignoring difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.
*/
if ("nocase".equalsIgnoreCase(flag) || "NC".equalsIgnoreCase(flag)) {
rule.setFromCaseSensitive(false);
}
/*
# 'noescape|NE' (no URI escaping of output)
This flag prevents mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from happening. This allows percent symbols to appear in the output, as in
RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'.
*/
if ("noescape".equalsIgnoreCase(flag) || "NE".equalsIgnoreCase(flag)) {
rule.setEncodeToUrl(false);
}
/*
# 'nosubreq|NS' ( not for internal sub-requests)
This flag forces the rewrite engine to skip a rewrite rule if the current request is an internal sub-request. For instance, sub-requests occur internally in Apache when mod_include tries to find out information about possible directory default files (index.xxx). On sub-requests it is not always useful, and can even cause errors, if the complete set of rules are applied. Use this flag to exclude some rules.
To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on sub-requests. In these cases, use this flag.
*/
if ("nosubreq".equalsIgnoreCase(flag) || "NS".equalsIgnoreCase(flag)) {
log.info("nosubreq flag [NS] not supported");
}
/*
# 'proxy|P' (force proxy)
This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here) put through the proxy module. You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the Apache proxy module. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.
Note: mod_proxy must be enabled in order to use this flag.
*/
if ("proxy".equalsIgnoreCase(flag) || "P".equalsIgnoreCase(flag)) {
rule.setToType("proxy");
}
/*
# 'passthrough|PT' (pass through to next handler)
This flag forces the rewrite engine to set the uri field of the internal request_rec structure to the value of the filename field. This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators. For example, to rewrite /abc to /def using mod_rewrite, and then /def to /ghi using mod_alias:
RewriteRule ^/abc(.*) /def$1 [PT]
Alias /def /ghi
If you omit the PT flag, mod_rewrite will rewrite uri=/abc/... to filename=/def/... as a full API-compliant URI-to-filename translator should do. Then mod_alias will try to do a URI-to-filename transition, which will fail.
Note: You must use this flag if you want to mix directives from different modules which allow URL-to-filename translators. The typical example is the use of mod_alias and mod_rewrite.
*/
if ("passthrough".equalsIgnoreCase(flag) || "PT".equalsIgnoreCase(flag)) {
rule.setToType("forward");
}
/*
# 'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
*/
if ("qsappend".equalsIgnoreCase(flag) || "QSA".equalsIgnoreCase(flag)) {
log.info("qsappend flag [QSA] not supported");
}
/*
# 'redirect|R [=code]' (force redirect)
Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a slash to /u/user, etc.
Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag.
*/
if ("redirect".equalsIgnoreCase(flag) || "R".equalsIgnoreCase(flag)) {
if ("301".equals(flagValue)) {
rule.setToType("permanent-redirect");
} else if ("302".equals(flagValue)) {
rule.setToType("temporary-redirect");
} else {
rule.setToType("redirect");
}
}
/*
# 'skip|S=num' (skip next rule(s))
This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)
*/
if ("skip".equalsIgnoreCase(flag) || "S".equalsIgnoreCase(flag)) {
log.info("Skip flag [S] not supported");
}
/*
# 'type|T=MIME-type' (force MIME type)
Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:
*/
if ("type".equalsIgnoreCase(flag) || "T".equalsIgnoreCase(flag)) {
SetAttribute set = new SetAttribute();
set.setType("content-type");
set.setValue(flagValue);
rule.addSetAttribute(set);
}
}
} else {
log.error("cannot parse flags from " + part);
}
}
private Condition processRewriteCond(String rewriteCondLine) {
log.debug("about to parse condition");
Condition condition = new Condition();
Matcher condMatcher = CONDITION_PATTERN.matcher(rewriteCondLine);
if (condMatcher.matches()) {
String conditionParts = StringUtils.trimToNull(condMatcher.group(1));
if (conditionParts != null) {
String[] condParts = conditionParts.split(" ");
for (int i = 0; i < condParts.length; i++) {
String part = StringUtils.trimToNull(condParts[i]);
if (part == null) continue;
if (part.equalsIgnoreCase("%{HTTP_USER_AGENT}")) {
condition.setType("header");
condition.setName("user-agent");
} else if (part.equalsIgnoreCase("%{HTTP_REFERER}")) {
condition.setType("header");
condition.setName("referer");
} else if (part.equalsIgnoreCase("%{HTTP_COOKIE}")) {
condition.setType("header");
condition.setName("cookie");
} else if (part.equalsIgnoreCase("%{HTTP_FORWARDED}")) {
condition.setType("header");
condition.setName("forwarded");
} else if (part.equalsIgnoreCase("%{HTTP_PROXY_CONNECTION}")) {
condition.setType("header");
condition.setName("proxy-connection");
} else if (part.equalsIgnoreCase("%{HTTP_ACCEPT}")) {
condition.setType("header");
condition.setName("accept");
} else if (part.equalsIgnoreCase("%{HTTP_HOST}")) {
condition.setType("server-name");
} else if (part.equalsIgnoreCase("%{REMOTE_ADDR}")) {
condition.setType("remote-addr");
} else if (part.equalsIgnoreCase("%{REMOTE_HOST}")) {
condition.setType("remote-host");
} else if (part.equalsIgnoreCase("%{REMOTE_USER}")) {
condition.setType("remote-user");
} else if (part.equalsIgnoreCase("%{REQUEST_METHOD}")) {
condition.setType("method");
} else if (part.equalsIgnoreCase("%{QUERY_STRING}")) {
condition.setType("query-string");
} else if (part.equalsIgnoreCase("%{TIME_YEAR}")) {
condition.setType("year");
} else if (part.equalsIgnoreCase("%{TIME_MON}")) {
condition.setType("month");
} else if (part.equalsIgnoreCase("%{TIME_DAY}")) {
condition.setType("dayofmonth");
} else if (part.equalsIgnoreCase("%{TIME_WDAY}")) {
condition.setType("dayofweek");
} else if (part.equalsIgnoreCase("%{TIME_HOUR}")) {
condition.setType("hourofday");
} else if (part.equalsIgnoreCase("%{TIME_MIN}")) {
condition.setType("minute");
} else if (part.equalsIgnoreCase("%{TIME_SEC}")) {
condition.setType("second");
} else if (part.equalsIgnoreCase("%{PATH_INFO}")) {
condition.setType("path-info");
} else if (part.equalsIgnoreCase("%{AUTH_TYPE}")) {
condition.setType("auth-type");
} else if (part.equalsIgnoreCase("%{SERVER_PORT}")) {
condition.setType("port");
//todo: bits below this comment
} else if (part.equalsIgnoreCase("%{REMOTE_PORT}")) {
log.error("REMOTE_PORT currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{REMOTE_IDENT}")) {
log.error("REMOTE_IDENT currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{SCRIPT_FILENAME}")) {
log.error("SCRIPT_FILENAME currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{DOCUMENT_ROOT}")) {
log.error("DOCUMENT_ROOT currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{SERVER_ADMIN}")) {
log.error("SERVER_ADMIN currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{SERVER_NAME}")) {
log.error("SERVER_NAME currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{SERVER_ADDR}")) {
log.error("SERVER_ADDR currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{SERVER_PROTOCOL}")) {
log.error("SERVER_PROTOCOL currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{SERVER_SOFTWARE}")) {
log.error("SERVER_SOFTWARE currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{TIME}")) {
log.error("TIME currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{API_VERSION}")) {
log.error("API_VERSION currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{THE_REQUEST}")) {
log.error("THE_REQUEST currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{REQUEST_URI}")) {
log.error("REQUEST_URI currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{REQUEST_FILENAME}")) {
log.error("REQUEST_FILENAME currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{IS_SUBREQ}")) {
log.error("IS_SUBREQ currently unsupported, ignoring");
} else if (part.equalsIgnoreCase("%{HTTPS}")) {
log.error("HTTPS currently unsupported, ignoring");
//todo: note https in mod_rewrite means "on" in URF land it means true
} else {
condition.setValue(part);
}
}
} else {
log.error("could not parse condition from " + rewriteCondLine);
}
} else {
log.error("cannot parse " + rewriteCondLine);
}
return condition;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -