Class RewriteRule
- java.lang.Object
- 
- org.apache.catalina.valves.rewrite.RewriteRule
 
- 
 public class RewriteRule extends java.lang.Object
- 
- 
Field SummaryFields Modifier and Type Field Description protected booleanchainThis flag chains the current rule with the next rule (which itself can be chained with the following rule, etc.).protected RewriteCond[]conditionsprotected booleancookieThis sets a cookie on the client's browser.protected java.lang.StringcookieDomainprotected booleancookieHttpOnlyprotected intcookieLifetimeprotected java.lang.StringcookieNameprotected java.lang.StringcookiePathprotected java.lang.ThreadLocal<java.lang.String>cookieResultprotected booleancookieSecureprotected SubstitutioncookieSubstitutionprotected java.lang.StringcookieValueprotected booleanenvThis forces a request attribute named VAR to be set to the value VAL, where VAL can contain regexp back references $N and %N which will be expanded.protected java.util.ArrayList<java.lang.String>envNameprotected java.util.ArrayList<java.lang.ThreadLocal<java.lang.String>>envResultprotected java.util.ArrayList<Substitution>envSubstitutionprotected java.util.ArrayList<java.lang.String>envValueprotected java.lang.StringflagsStringprotected booleanforbiddenThis forces the current URL to be forbidden, i.e., it immediately sends back an HTTP response of 403 (FORBIDDEN).protected booleangoneThis forces the current URL to be gone, i.e., it immediately sends back an HTTP response of 410 (GONE).protected booleanhostHost.protected booleanlastStop the rewriting process here and don't apply any more rewriting rules.protected booleannextRe-run the rewriting process (starting again with the first rewriting rule).protected booleannocaseThis makes the Pattern case-insensitive, i.e., there is no difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.protected booleannoescapeThis flag keeps mod_rewrite from applying the usual URI escaping rules to the result of a rewrite.protected booleannosubreqThis flag forces the rewriting engine to skip a rewriting rule if the current request is an internal sub-request.protected java.lang.ThreadLocal<java.util.regex.Pattern>patternprotected java.lang.StringpatternStringprotected booleanpositiveprotected booleanqsappendThis flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it.protected booleanqsdiscardWhen the requested URI contains a query string, and the target URI does not, the default behavior of RewriteRule is to copy that query string to the target URI.protected booleanredirectPrefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force an external redirection.protected intredirectCodeprotected intskipThis flag forces the rewriting engine to skip the next num rules in sequence when the current rule matches.protected Substitutionsubstitutionprotected java.lang.StringsubstitutionStringprotected booleantypeForce the MIME-type of the target file to be MIME-type.protected java.lang.StringtypeValue
 - 
Constructor SummaryConstructors Constructor Description RewriteRule()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCondition(RewriteCond condition)voidaddEnvName(java.lang.String envName)voidaddEnvValue(java.lang.String envValue)java.lang.CharSequenceevaluate(java.lang.CharSequence url, Resolver resolver)Evaluate the rule based on the contextRewriteCond[]getConditions()java.lang.StringgetCookieDomain()intgetCookieLifetime()java.lang.StringgetCookieName()java.lang.StringgetCookiePath()java.lang.StringgetCookieResult()java.lang.StringgetCookieValue()java.lang.StringgetEnvName(int i)java.lang.StringgetEnvResult(int i)intgetEnvSize()java.lang.StringgetEnvValue(int i)java.lang.StringgetFlagsString()java.lang.StringgetPatternString()intgetRedirectCode()intgetSkip()SubstitutiongetSubstitution()java.lang.StringgetSubstitutionString()java.lang.StringgetTypeValue()booleanisChain()booleanisCookie()booleanisCookieHttpOnly()booleanisCookieSecure()booleanisEnv()booleanisEscapeBackReferences()booleanisForbidden()booleanisGone()booleanisHost()booleanisLast()booleanisNext()booleanisNocase()booleanisNoescape()booleanisNosubreq()booleanisQsappend()booleanisQsdiscard()booleanisRedirect()booleanisType()voidparse(java.util.Map<java.lang.String,RewriteMap> maps)voidsetChain(boolean chain)voidsetConditions(RewriteCond[] conditions)voidsetCookie(boolean cookie)voidsetCookieDomain(java.lang.String cookieDomain)voidsetCookieHttpOnly(boolean cookieHttpOnly)voidsetCookieLifetime(int cookieLifetime)voidsetCookieName(java.lang.String cookieName)voidsetCookiePath(java.lang.String cookiePath)voidsetCookieSecure(boolean cookieSecure)voidsetCookieValue(java.lang.String cookieValue)voidsetEnv(boolean env)voidsetEscapeBackReferences(boolean escapeBackReferences)voidsetFlagsString(java.lang.String flagsString)voidsetForbidden(boolean forbidden)voidsetGone(boolean gone)voidsetHost(boolean host)voidsetLast(boolean last)voidsetNext(boolean next)voidsetNocase(boolean nocase)voidsetNoescape(boolean noescape)voidsetNosubreq(boolean nosubreq)voidsetPatternString(java.lang.String patternString)voidsetQsappend(boolean qsappend)voidsetQsdiscard(boolean qsdiscard)voidsetRedirect(boolean redirect)voidsetRedirectCode(int redirectCode)voidsetSkip(int skip)voidsetSubstitution(Substitution substitution)voidsetSubstitutionString(java.lang.String substitutionString)voidsetType(boolean type)voidsetTypeValue(java.lang.String typeValue)java.lang.StringtoString()String representation.
 
- 
- 
- 
Field Detail- 
conditionsprotected RewriteCond[] conditions 
 - 
patternprotected java.lang.ThreadLocal<java.util.regex.Pattern> pattern 
 - 
substitutionprotected Substitution substitution 
 - 
patternStringprotected java.lang.String patternString 
 - 
substitutionStringprotected java.lang.String substitutionString 
 - 
flagsStringprotected java.lang.String flagsString 
 - 
positiveprotected boolean positive 
 - 
chainprotected boolean chain This flag chains the current rule with the next rule (which itself can be chained with the following rule, etc.). This has the following effect: if a rule matches, then processing continues as usual, i.e., the flag has no effect. If the rule does not match, then all following chained rules are skipped. For instance, use it to remove the ".www" part inside a per-directory rule set when you let an external redirect happen (where the ".www" part should not to occur!).
 - 
cookieprotected boolean cookie This sets a cookie on the client's browser. The cookie's name is specified by NAME and the value is VAL. 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
 - 
cookieNameprotected java.lang.String cookieName 
 - 
cookieValueprotected java.lang.String cookieValue 
 - 
cookieDomainprotected java.lang.String cookieDomain 
 - 
cookieLifetimeprotected int cookieLifetime 
 - 
cookiePathprotected java.lang.String cookiePath 
 - 
cookieSecureprotected boolean cookieSecure 
 - 
cookieHttpOnlyprotected boolean cookieHttpOnly 
 - 
cookieSubstitutionprotected Substitution cookieSubstitution 
 - 
cookieResultprotected java.lang.ThreadLocal<java.lang.String> cookieResult 
 - 
envprotected boolean env This forces a request attribute named VAR to be set to the value VAL, where VAL can contain regexp back references $N and %N which will be expanded. Multiple env flags are allowed.
 - 
envNameprotected java.util.ArrayList<java.lang.String> envName 
 - 
envValueprotected java.util.ArrayList<java.lang.String> envValue 
 - 
envSubstitutionprotected java.util.ArrayList<Substitution> envSubstitution 
 - 
envResultprotected java.util.ArrayList<java.lang.ThreadLocal<java.lang.String>> envResult 
 - 
forbiddenprotected boolean forbidden This forces the current URL to be forbidden, i.e., it immediately sends back an HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to conditionally block some URLs.
 - 
goneprotected boolean gone This forces the current URL to be gone, i.e., it immediately sends back an HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.
 - 
hostprotected boolean host Host. This means this rule and its associated conditions will apply to host, allowing host rewriting (ex: redirecting internally *.foo.com to bar.foo.com).
 - 
lastprotected boolean last Stop the rewriting process here and don't apply any more rewriting rules. This corresponds to the Perl last command or the break command from the C language. 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/'.
 - 
nextprotected boolean next Re-run the rewriting process (starting again with the first rewriting rule). Here the URL to match is again not the original URL but the URL from the last rewriting rule. This corresponds to the Perl next command or the continue command from the C language. Use this flag to restart the rewriting process, i.e., to immediately go to the top of the loop. But be careful not to create an infinite loop!
 - 
nocaseprotected boolean nocase This makes the Pattern case-insensitive, i.e., there is no difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.
 - 
noescapeprotected boolean noescape This flag keeps 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 being done. 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'.
 - 
nosubreqprotected boolean nosubreq This flag forces the rewriting engine to skip a rewriting 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 even sometimes causes a failure to if the complete set of rules are applied. Use this flag to exclude some rules. Use the following rule for your decision: whenever you prefix some URLs with CGI-scripts to force them to be processed by the CGI-script, the chance is high that you will run into problems (or even overhead) on sub-requests. In these cases, use this flag.
 - 
qsappendprotected boolean qsappend This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
 - 
qsdiscardprotected boolean qsdiscard When the requested URI contains a query string, and the target URI does not, the default behavior of RewriteRule is to copy that query string to the target URI. Using the [QSD] flag causes the query string to be discarded. Using [QSD] and [QSA] together will result in [QSD] taking precedence.
 - 
redirectprotected boolean redirect Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force an external redirection. If no code is given an HTTP response of 302 (FOUND, previously MOVED TEMPORARILY) is used. If you want to use other response codes in the range 300-399 just specify them as a number or use one of the following symbolic names: temp (default), permanent, seeother. Use it for rules which should canonicalize the URL and give it back to the client, e.g., translate "/~" into "/u/" or always append a slash to /u/user, etc. Note: When you use this flag, make sure that the substitution field is a valid URL! If not, you are redirecting to an invalid location! And remember that this flag itself only prefixes the URL with http://thishost[:thisport]/, rewriting continues. Usually you also want to stop and do the redirection immediately. To stop the rewriting you also have to provide the 'L' flag.
 - 
redirectCodeprotected int redirectCode 
 - 
skipprotected int skip This flag forces the rewriting engine to skip the next num rules in sequence when 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!)
 - 
typeprotected boolean type Force the MIME-type of the target file to be MIME-type. For instance, this can be used to setup 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: RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
 - 
typeValueprotected java.lang.String typeValue 
 
- 
 - 
Method Detail- 
parsepublic void parse(java.util.Map<java.lang.String,RewriteMap> maps) 
 - 
addConditionpublic void addCondition(RewriteCond condition) 
 - 
evaluatepublic java.lang.CharSequence evaluate(java.lang.CharSequence url, Resolver resolver)Evaluate the rule based on the context- Parameters:
- url- The char sequence
- resolver- Property resolver
- Returns:
- nullif no rewrite took place
 
 - 
toStringpublic java.lang.String toString() String representation.- Overrides:
- toStringin class- java.lang.Object
 
 - 
isEscapeBackReferencespublic boolean isEscapeBackReferences() 
 - 
setEscapeBackReferencespublic void setEscapeBackReferences(boolean escapeBackReferences) 
 - 
isChainpublic boolean isChain() 
 - 
setChainpublic void setChain(boolean chain) 
 - 
getConditionspublic RewriteCond[] getConditions() 
 - 
setConditionspublic void setConditions(RewriteCond[] conditions) 
 - 
isCookiepublic boolean isCookie() 
 - 
setCookiepublic void setCookie(boolean cookie) 
 - 
getCookieNamepublic java.lang.String getCookieName() 
 - 
setCookieNamepublic void setCookieName(java.lang.String cookieName) 
 - 
getCookieValuepublic java.lang.String getCookieValue() 
 - 
setCookieValuepublic void setCookieValue(java.lang.String cookieValue) 
 - 
getCookieResultpublic java.lang.String getCookieResult() 
 - 
isEnvpublic boolean isEnv() 
 - 
getEnvSizepublic int getEnvSize() 
 - 
setEnvpublic void setEnv(boolean env) 
 - 
getEnvNamepublic java.lang.String getEnvName(int i) 
 - 
addEnvNamepublic void addEnvName(java.lang.String envName) 
 - 
getEnvValuepublic java.lang.String getEnvValue(int i) 
 - 
addEnvValuepublic void addEnvValue(java.lang.String envValue) 
 - 
getEnvResultpublic java.lang.String getEnvResult(int i) 
 - 
isForbiddenpublic boolean isForbidden() 
 - 
setForbiddenpublic void setForbidden(boolean forbidden) 
 - 
isGonepublic boolean isGone() 
 - 
setGonepublic void setGone(boolean gone) 
 - 
isLastpublic boolean isLast() 
 - 
setLastpublic void setLast(boolean last) 
 - 
isNextpublic boolean isNext() 
 - 
setNextpublic void setNext(boolean next) 
 - 
isNocasepublic boolean isNocase() 
 - 
setNocasepublic void setNocase(boolean nocase) 
 - 
isNoescapepublic boolean isNoescape() 
 - 
setNoescapepublic void setNoescape(boolean noescape) 
 - 
isNosubreqpublic boolean isNosubreq() 
 - 
setNosubreqpublic void setNosubreq(boolean nosubreq) 
 - 
isQsappendpublic boolean isQsappend() 
 - 
setQsappendpublic void setQsappend(boolean qsappend) 
 - 
isQsdiscardpublic final boolean isQsdiscard() 
 - 
setQsdiscardpublic final void setQsdiscard(boolean qsdiscard) 
 - 
isRedirectpublic boolean isRedirect() 
 - 
setRedirectpublic void setRedirect(boolean redirect) 
 - 
getRedirectCodepublic int getRedirectCode() 
 - 
setRedirectCodepublic void setRedirectCode(int redirectCode) 
 - 
getSkippublic int getSkip() 
 - 
setSkippublic void setSkip(int skip) 
 - 
getSubstitutionpublic Substitution getSubstitution() 
 - 
setSubstitutionpublic void setSubstitution(Substitution substitution) 
 - 
isTypepublic boolean isType() 
 - 
setTypepublic void setType(boolean type) 
 - 
getTypeValuepublic java.lang.String getTypeValue() 
 - 
setTypeValuepublic void setTypeValue(java.lang.String typeValue) 
 - 
getPatternStringpublic java.lang.String getPatternString() 
 - 
setPatternStringpublic void setPatternString(java.lang.String patternString) 
 - 
getSubstitutionStringpublic java.lang.String getSubstitutionString() 
 - 
setSubstitutionStringpublic void setSubstitutionString(java.lang.String substitutionString) 
 - 
getFlagsStringpublic final java.lang.String getFlagsString() 
 - 
setFlagsStringpublic final void setFlagsString(java.lang.String flagsString) 
 - 
isHostpublic boolean isHost() 
 - 
setHostpublic void setHost(boolean host) 
 - 
getCookieDomainpublic java.lang.String getCookieDomain() 
 - 
setCookieDomainpublic void setCookieDomain(java.lang.String cookieDomain) 
 - 
getCookieLifetimepublic int getCookieLifetime() 
 - 
setCookieLifetimepublic void setCookieLifetime(int cookieLifetime) 
 - 
getCookiePathpublic java.lang.String getCookiePath() 
 - 
setCookiePathpublic void setCookiePath(java.lang.String cookiePath) 
 - 
isCookieSecurepublic boolean isCookieSecure() 
 - 
setCookieSecurepublic void setCookieSecure(boolean cookieSecure) 
 - 
isCookieHttpOnlypublic boolean isCookieHttpOnly() 
 - 
setCookieHttpOnlypublic void setCookieHttpOnly(boolean cookieHttpOnly) 
 
- 
 
-