Top Fields Constructors Methods
org.apache.catalina.valves.rewrite

public Class RewriteRule

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Map, java.util.regex.Matcher, .Pattern

Field Summary

Modifier and TypeField and Description
protected boolean
chain

This flag chains the current rule with the next rule (which itself can be chained with the following rule, etc.).

protected RewriteCond[]
protected boolean
cookie

This sets a cookie on the client's browser.

protected String
protected boolean
protected int
protected String
protected String
protected ThreadLocal<String>
protected boolean
protected Substitution
protected String
protected 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.

protected ArrayList<String>
protected ArrayList<ThreadLocal<String>>
protected ArrayList<Substitution>
protected ArrayList<String>
private boolean
protected String
protected boolean
forbidden

This forces the current URL to be forbidden, i.e., it immediately sends back an HTTP response of 403 (FORBIDDEN).

protected boolean
gone

This forces the current URL to be gone, i.e., it immediately sends back an HTTP response of 410 (GONE).

protected boolean
host

Host.

protected boolean
last

Stop the rewriting process here and don't apply any more rewriting rules.

protected boolean
next

Re-run the rewriting process (starting again with the first rewriting rule).

protected 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.

protected boolean
noescape

This flag keeps mod_rewrite from applying the usual URI escaping rules to the result of a rewrite.

protected boolean
nosubreq

This flag forces the rewriting engine to skip a rewriting rule if the current request is an internal sub-request.

protected ThreadLocal<Pattern>
protected String
protected boolean
protected 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.

protected 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.

protected boolean
redirect

Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force an external redirection.

protected int
protected int
skip

This flag forces the rewriting engine to skip the next num rules in sequence when the current rule matches.

protected Substitution
protected String
protected boolean
type

Force the MIME-type of the target file to be MIME-type.

protected String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
addEnvName(String envName)

public void
addEnvValue(String envValue)

public CharSequence

Returns:

null if no rewrite took place
evaluate
(CharSequence
The char sequence
url
,
Resolver
Property resolver
resolver
)

Evaluate the rule based on the context

public RewriteCond[]
public String
public int
public String
public String
public String
public String
public String
getEnvName(int i)

public String
getEnvResult(int i)

public int
public String
getEnvValue(int i)

public final String
public String
public int
public int
public Substitution
public String
public String
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public final boolean
public boolean
public boolean
public void
public void
setChain(boolean chain)

public void
setConditions(RewriteCond[] conditions)

public void
setCookie(boolean cookie)

public void
setCookieDomain(String cookieDomain)

public void
setCookieHttpOnly(boolean cookieHttpOnly)

public void
setCookieLifetime(int cookieLifetime)

public void
setCookieName(String cookieName)

public void
setCookiePath(String cookiePath)

public void
setCookieSecure(boolean cookieSecure)

public void
setCookieValue(String cookieValue)

public void
setEnv(boolean env)

public void
setEscapeBackReferences(boolean escapeBackReferences)

public final void
setFlagsString(String flagsString)

public void
setForbidden(boolean forbidden)

public void
setGone(boolean gone)

public void
setHost(boolean host)

public void
setLast(boolean last)

public void
setNext(boolean next)

public void
setNocase(boolean nocase)

public void
setNoescape(boolean noescape)

public void
setNosubreq(boolean nosubreq)

public void
setPatternString(String patternString)

public void
setQsappend(boolean qsappend)

public final void
setQsdiscard(boolean qsdiscard)

public void
setRedirect(boolean redirect)

public void
setRedirectCode(int redirectCode)

public void
setSkip(int skip)

public void
public void
setSubstitutionString(String substitutionString)

public void
setType(boolean type)

public void
setTypeValue(String typeValue)

public String
toString()

Overrides java.lang.Object.toString.

String representation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

chainback to summary
protected 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!).

conditionsback to summary
protected RewriteCond[] conditions
cookieDomainback to summary
protected String cookieDomain
cookieHttpOnlyback to summary
protected boolean cookieHttpOnly
cookieLifetimeback to summary
protected int cookieLifetime
cookieNameback to summary
protected String cookieName
cookiePathback to summary
protected String cookiePath
cookieResultback to summary
protected ThreadLocal<String> cookieResult
cookieSecureback to summary
protected boolean cookieSecure
cookieSubstitutionback to summary
protected Substitution cookieSubstitution
cookieValueback to summary
protected String cookieValue
envback to summary
protected 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.

envNameback to summary
protected ArrayList<String> envName
envResultback to summary
protected ArrayList<ThreadLocal<String>> envResult
envSubstitutionback to summary
protected ArrayList<Substitution> envSubstitution
envValueback to summary
protected ArrayList<String> envValue
escapeBackReferencesback to summary
private boolean escapeBackReferences
flagsStringback to summary
protected String flagsString
forbiddenback to summary
protected 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.

goneback to summary
protected 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.

hostback to summary
protected 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).

lastback to summary
protected 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/'.

nextback to summary
protected 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!

nocaseback to summary
protected 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.

noescapeback to summary
protected 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'.

nosubreqback to summary
protected 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.

patternback to summary
protected ThreadLocal<Pattern> pattern
patternStringback to summary
protected String patternString
positiveback to summary
protected boolean positive
qsappendback to summary
protected 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.

qsdiscardback to summary
protected 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.

redirectback to summary
protected 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.

redirectCodeback to summary
protected int redirectCode
skipback to summary
protected 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!)

substitutionback to summary
protected Substitution substitution
substitutionStringback to summary
protected String substitutionString
typeback to summary
protected 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]

typeValueback to summary
protected String typeValue

Constructor Detail

RewriteRuleback to summary
public RewriteRule()

Method Detail

addConditionback to summary
public void addCondition(RewriteCond condition)
addEnvNameback to summary
public void addEnvName(String envName)
addEnvValueback to summary
public void addEnvValue(String envValue)
evaluateback to summary
public CharSequence evaluate(CharSequence url, Resolver resolver)

Evaluate the rule based on the context

Parameters
url:CharSequence

The char sequence

resolver:Resolver

Property resolver

Returns:CharSequence

null if no rewrite took place

getConditionsback to summary
public RewriteCond[] getConditions()
getCookieDomainback to summary
public String getCookieDomain()
getCookieLifetimeback to summary
public int getCookieLifetime()
getCookieNameback to summary
public String getCookieName()
getCookiePathback to summary
public String getCookiePath()
getCookieResultback to summary
public String getCookieResult()
getCookieValueback to summary
public String getCookieValue()
getEnvNameback to summary
public String getEnvName(int i)
getEnvResultback to summary
public String getEnvResult(int i)
getEnvSizeback to summary
public int getEnvSize()
getEnvValueback to summary
public String getEnvValue(int i)
getFlagsStringback to summary
public final String getFlagsString()
getPatternStringback to summary
public String getPatternString()
getRedirectCodeback to summary
public int getRedirectCode()
getSkipback to summary
public int getSkip()
getSubstitutionback to summary
public Substitution getSubstitution()
getSubstitutionStringback to summary
public String getSubstitutionString()
getTypeValueback to summary
public String getTypeValue()
isChainback to summary
public boolean isChain()
isCookieback to summary
public boolean isCookie()
isCookieHttpOnlyback to summary
public boolean isCookieHttpOnly()
isCookieSecureback to summary
public boolean isCookieSecure()
isEnvback to summary
public boolean isEnv()
isEscapeBackReferencesback to summary
public boolean isEscapeBackReferences()
isForbiddenback to summary
public boolean isForbidden()
isGoneback to summary
public boolean isGone()
isHostback to summary
public boolean isHost()
isLastback to summary
public boolean isLast()
isNextback to summary
public boolean isNext()
isNocaseback to summary
public boolean isNocase()
isNoescapeback to summary
public boolean isNoescape()
isNosubreqback to summary
public boolean isNosubreq()
isQsappendback to summary
public boolean isQsappend()
isQsdiscardback to summary
public final boolean isQsdiscard()
isRedirectback to summary
public boolean isRedirect()
isTypeback to summary
public boolean isType()
parseback to summary
public void parse(Map<String, RewriteMap> maps)
setChainback to summary
public void setChain(boolean chain)
setConditionsback to summary
public void setConditions(RewriteCond[] conditions)
setCookieback to summary
public void setCookie(boolean cookie)
setCookieDomainback to summary
public void setCookieDomain(String cookieDomain)
setCookieHttpOnlyback to summary
public void setCookieHttpOnly(boolean cookieHttpOnly)
setCookieLifetimeback to summary
public void setCookieLifetime(int cookieLifetime)
setCookieNameback to summary
public void setCookieName(String cookieName)
setCookiePathback to summary
public void setCookiePath(String cookiePath)
setCookieSecureback to summary
public void setCookieSecure(boolean cookieSecure)
setCookieValueback to summary
public void setCookieValue(String cookieValue)
setEnvback to summary
public void setEnv(boolean env)
setEscapeBackReferencesback to summary
public void setEscapeBackReferences(boolean escapeBackReferences)
setFlagsStringback to summary
public final void setFlagsString(String flagsString)
setForbiddenback to summary
public void setForbidden(boolean forbidden)
setGoneback to summary
public void setGone(boolean gone)
setHostback to summary
public void setHost(boolean host)
setLastback to summary
public void setLast(boolean last)
setNextback to summary
public void setNext(boolean next)
setNocaseback to summary
public void setNocase(boolean nocase)
setNoescapeback to summary
public void setNoescape(boolean noescape)
setNosubreqback to summary
public void setNosubreq(boolean nosubreq)
setPatternStringback to summary
public void setPatternString(String patternString)
setQsappendback to summary
public void setQsappend(boolean qsappend)
setQsdiscardback to summary
public final void setQsdiscard(boolean qsdiscard)
setRedirectback to summary
public void setRedirect(boolean redirect)
setRedirectCodeback to summary
public void setRedirectCode(int redirectCode)
setSkipback to summary
public void setSkip(int skip)
setSubstitutionback to summary
public void setSubstitution(Substitution substitution)
setSubstitutionStringback to summary
public void setSubstitutionString(String substitutionString)
setTypeback to summary
public void setType(boolean type)
setTypeValueback to summary
public void setTypeValue(String typeValue)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

String representation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override