Package org.apache.catalina.valves.rewrite

# Class RewriteRule

java.lang.Object
org.apache.catalina.valves.rewrite.RewriteRule

public class RewriteRule extends Object

- ## Field Summary

  Fields
  Modifier and Type
  Field
  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[]`
  `conditions`
  `protected boolean`
  `cookie`
  This sets a cookie on the client's browser.
  `protected String`
  `cookieDomain`
  `protected boolean`
  `cookieHttpOnly`
  `protected int`
  `cookieLifetime`
  `protected String`
  `cookieName`
  `protected String`
  `cookiePath`
  `protected ThreadLocal<String>`
  `cookieResult`
  `protected boolean`
  `cookieSecure`
  `protected Substitution`
  `cookieSubstitution`
  `protected String`
  `cookieValue`
  `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>`
  `envName`
  `protected ArrayList<ThreadLocal<String>>`
  `envResult`
  `protected ArrayList<Substitution>`
  `envSubstitution`
  `protected ArrayList<String>`
  `envValue`
  `protected String`
  `flagsString`
  `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>`
  `pattern`
  `protected String`
  `patternString`
  `protected boolean`
  `positive`
  `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`
  `redirectCode`
  `protected int`
  `skip`
  This flag forces the rewriting engine to skip the next num rules in sequence when the current rule matches.
  `protected Substitution`
  `substitution`
  `protected String`
  `substitutionString`
  `protected boolean`
  `type`
  Force the MIME-type of the target file to be MIME-type.
  `protected String`
  `typeValue`
  `protected boolean`
  `valveSkip`
  Allows skipping the next valve in the Catalina pipeline.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RewriteRule()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addCondition(RewriteCond condition)`
  `void`
  `addEnvName(String envName)`
  `void`
  `addEnvValue(String envValue)`
  `CharSequence`
  `evaluate(CharSequence url, Resolver resolver)`
  Evaluate the rule based on the context
  `RewriteCond[]`
  `getConditions()`
  `String`
  `getCookieDomain()`
  `int`
  `getCookieLifetime()`
  `String`
  `getCookieName()`
  `String`
  `getCookiePath()`
  `String`
  `getCookieResult()`
  `String`
  `getCookieValue()`
  `String`
  `getEnvName(int i)`
  `String`
  `getEnvResult(int i)`
  `int`
  `getEnvSize()`
  `String`
  `getEnvValue(int i)`
  `final String`
  `getFlagsString()`
  `String`
  `getPatternString()`
  `int`
  `getRedirectCode()`
  `int`
  `getSkip()`
  `Substitution`
  `getSubstitution()`
  `String`
  `getSubstitutionString()`
  `String`
  `getTypeValue()`
  `boolean`
  `isChain()`
  `boolean`
  `isCookie()`
  `boolean`
  `isCookieHttpOnly()`
  `boolean`
  `isCookieSecure()`
  `boolean`
  `isEnv()`
  `boolean`
  `isEscapeBackReferences()`
  `boolean`
  `isForbidden()`
  `boolean`
  `isGone()`
  `boolean`
  `isHost()`
  `boolean`
  `isLast()`
  `boolean`
  `isNext()`
  `boolean`
  `isNocase()`
  `boolean`
  `isNoescape()`
  `boolean`
  `isNosubreq()`
  `boolean`
  `isQsappend()`
  `final boolean`
  `isQsdiscard()`
  `boolean`
  `isRedirect()`
  `boolean`
  `isType()`
  `boolean`
  `isValveSkip()`
  `void`
  `parse(Map<String,RewriteMap> maps)`
  `void`
  `setChain(boolean chain)`
  `void`
  `setConditions(RewriteCond[] conditions)`
  `void`
  `setCookie(boolean cookie)`
  `void`
  `setCookieDomain(String cookieDomain)`
  `void`
  `setCookieHttpOnly(boolean cookieHttpOnly)`
  `void`
  `setCookieLifetime(int cookieLifetime)`
  `void`
  `setCookieName(String cookieName)`
  `void`
  `setCookiePath(String cookiePath)`
  `void`
  `setCookieSecure(boolean cookieSecure)`
  `void`
  `setCookieValue(String cookieValue)`
  `void`
  `setEnv(boolean env)`
  `void`
  `setEscapeBackReferences(boolean escapeBackReferences)`
  `final void`
  `setFlagsString(String flagsString)`
  `void`
  `setForbidden(boolean forbidden)`
  `void`
  `setGone(boolean gone)`
  `void`
  `setHost(boolean host)`
  `void`
  `setLast(boolean last)`
  `void`
  `setNext(boolean next)`
  `void`
  `setNocase(boolean nocase)`
  `void`
  `setNoescape(boolean noescape)`
  `void`
  `setNosubreq(boolean nosubreq)`
  `void`
  `setPatternString(String patternString)`
  `void`
  `setQsappend(boolean qsappend)`
  `final void`
  `setQsdiscard(boolean qsdiscard)`
  `void`
  `setRedirect(boolean redirect)`
  `void`
  `setRedirectCode(int redirectCode)`
  `void`
  `setSkip(int skip)`
  `void`
  `setSubstitution(Substitution substitution)`
  `void`
  `setSubstitutionString(String substitutionString)`
  `void`
  `setType(boolean type)`
  `void`
  `setTypeValue(String typeValue)`
  `void`
  `setValveSkip(boolean valveSkip)`
  `String`
  `toString()`
  String representation.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### conditions

    protected RewriteCond[] conditions

  - ### pattern

    protected ThreadLocal<Pattern> pattern

  - ### substitution

    protected Substitution substitution

  - ### patternString

    protected String patternString

  - ### substitutionString

    protected String substitutionString

  - ### flagsString

    protected String flagsString

  - ### positive

    protected boolean positive

  - ### chain

    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!).

  - ### cookie

    protected 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

  - ### cookieName

    protected String cookieName

  - ### cookieValue

    protected String cookieValue

  - ### cookieDomain

    protected String cookieDomain

  - ### cookieLifetime

    protected int cookieLifetime

  - ### cookiePath

    protected String cookiePath

  - ### cookieSecure

    protected boolean cookieSecure

  - ### cookieHttpOnly

    protected boolean cookieHttpOnly

  - ### cookieSubstitution

    protected Substitution cookieSubstitution

  - ### cookieResult

    protected ThreadLocal<String> cookieResult

  - ### env

    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.

  - ### envName

    protected ArrayList<String> envName

  - ### envValue

    protected ArrayList<String> envValue

  - ### envSubstitution

    protected ArrayList<Substitution> envSubstitution

  - ### envResult

    protected ArrayList<ThreadLocal<String>> envResult

  - ### forbidden

    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.

  - ### gone

    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.

  - ### host

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

  - ### last

    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/'.

  - ### next

    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!

  - ### nocase

    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.

  - ### noescape

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

  - ### nosubreq

    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.

  - ### qsappend

    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.

  - ### qsdiscard

    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.

  - ### redirect

    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.

  - ### redirectCode

    protected int redirectCode

  - ### skip

    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!)

  - ### type

    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]

  - ### typeValue

    protected String typeValue

  - ### valveSkip

    protected boolean valveSkip
    Allows skipping the next valve in the Catalina pipeline.

- ## Constructor Details

  - ### RewriteRule

    public RewriteRule()

- ## Method Details

  - ### parse

    public void parse(Map<String,RewriteMap> maps)

  - ### addCondition

    public void addCondition(RewriteCond condition)

  - ### evaluate

    public CharSequence evaluate(CharSequence url, Resolver resolver)
    Evaluate the rule based on the context
    Parameters:
      `url` - The char sequence
      `resolver` - Property resolver
    Returns:
      `null` if no rewrite took place

  - ### toString

    public String toString()
    String representation.
    Overrides:
      `toString` in class `Object`

  - ### isEscapeBackReferences

    public boolean isEscapeBackReferences()

  - ### setEscapeBackReferences

    public void setEscapeBackReferences(boolean escapeBackReferences)

  - ### isChain

    public boolean isChain()

  - ### setChain

    public void setChain(boolean chain)

  - ### getConditions

    public RewriteCond[] getConditions()

  - ### setConditions

    public void setConditions(RewriteCond[] conditions)

  - ### isCookie

    public boolean isCookie()

  - ### setCookie

    public void setCookie(boolean cookie)

  - ### getCookieName

    public String getCookieName()

  - ### setCookieName

    public void setCookieName(String cookieName)

  - ### getCookieValue

    public String getCookieValue()

  - ### setCookieValue

    public void setCookieValue(String cookieValue)

  - ### getCookieResult

    public String getCookieResult()

  - ### isEnv

    public boolean isEnv()

  - ### getEnvSize

    public int getEnvSize()

  - ### setEnv

    public void setEnv(boolean env)

  - ### getEnvName

    public String getEnvName(int i)

  - ### addEnvName

    public void addEnvName(String envName)

  - ### getEnvValue

    public String getEnvValue(int i)

  - ### addEnvValue

    public void addEnvValue(String envValue)

  - ### getEnvResult

    public String getEnvResult(int i)

  - ### isForbidden

    public boolean isForbidden()

  - ### setForbidden

    public void setForbidden(boolean forbidden)

  - ### isGone

    public boolean isGone()

  - ### setGone

    public void setGone(boolean gone)

  - ### isLast

    public boolean isLast()

  - ### setLast

    public void setLast(boolean last)

  - ### isNext

    public boolean isNext()

  - ### setNext

    public void setNext(boolean next)

  - ### isNocase

    public boolean isNocase()

  - ### setNocase

    public void setNocase(boolean nocase)

  - ### isNoescape

    public boolean isNoescape()

  - ### setNoescape

    public void setNoescape(boolean noescape)

  - ### isNosubreq

    public boolean isNosubreq()

  - ### setNosubreq

    public void setNosubreq(boolean nosubreq)

  - ### isQsappend

    public boolean isQsappend()

  - ### setQsappend

    public void setQsappend(boolean qsappend)

  - ### isQsdiscard

    public final boolean isQsdiscard()

  - ### setQsdiscard

    public final void setQsdiscard(boolean qsdiscard)

  - ### isRedirect

    public boolean isRedirect()

  - ### setRedirect

    public void setRedirect(boolean redirect)

  - ### getRedirectCode

    public int getRedirectCode()

  - ### setRedirectCode

    public void setRedirectCode(int redirectCode)

  - ### getSkip

    public int getSkip()

  - ### setSkip

    public void setSkip(int skip)

  - ### getSubstitution

    public Substitution getSubstitution()

  - ### setSubstitution

    public void setSubstitution(Substitution substitution)

  - ### isType

    public boolean isType()

  - ### setType

    public void setType(boolean type)

  - ### getTypeValue

    public String getTypeValue()

  - ### setTypeValue

    public void setTypeValue(String typeValue)

  - ### getPatternString

    public String getPatternString()

  - ### setPatternString

    public void setPatternString(String patternString)

  - ### getSubstitutionString

    public String getSubstitutionString()

  - ### setSubstitutionString

    public void setSubstitutionString(String substitutionString)

  - ### getFlagsString

    public final String getFlagsString()

  - ### setFlagsString

    public final void setFlagsString(String flagsString)

  - ### isHost

    public boolean isHost()

  - ### setHost

    public void setHost(boolean host)

  - ### getCookieDomain

    public String getCookieDomain()

  - ### setCookieDomain

    public void setCookieDomain(String cookieDomain)

  - ### getCookieLifetime

    public int getCookieLifetime()

  - ### setCookieLifetime

    public void setCookieLifetime(int cookieLifetime)

  - ### getCookiePath

    public String getCookiePath()

  - ### setCookiePath

    public void setCookiePath(String cookiePath)

  - ### isCookieSecure

    public boolean isCookieSecure()

  - ### setCookieSecure

    public void setCookieSecure(boolean cookieSecure)

  - ### isCookieHttpOnly

    public boolean isCookieHttpOnly()

  - ### setCookieHttpOnly

    public void setCookieHttpOnly(boolean cookieHttpOnly)

  - ### isValveSkip

    public boolean isValveSkip()

  - ### setValveSkip

    public void setValveSkip(boolean valveSkip)