- Introduction
- Installation
- Working with ISAPI_Rewrite
- ISAPI_Rewrite directives
- Examples
- Troubleshooting
- Release notes
RewriteCond directive
Description: | Defines a condition for the subsequent RewriteRule |
Syntax: | RewriteCond TestString CondPattern |
Context: | server config, virtual host, directory, .htaccess |
This directive defines a single condition for the following RewriteRule, RewriteHeader or RewriteProxy directive. There can be one or more conditions preceding a rule directive and the rule will only apply if all of the conditions are met.
TestString additionally to plain text can contain the following constructs:
- Back references to RewriteRule pattern using syntax $N.
- Back references to preceding RewriteCond patterns using syntax %N.
- RewriteMap expansions using syntax ${mapname:key|default}.
- HTTP header value with the syntax %{HTTP:header}.
- Server variable using the syntax %{ NAME_OF_VARIABLE }.
Here is a list of available server variables:|
HTTP_USER_AGENT
HTTP_REFERER
HTTP_COOKIE
HTTP_FORWARDED
HTTP_HOST
HTTP_PROXY_CONNECTION
HTTP_ACCEPT
REMOTE_ADDR
REMOTE_HOST
REMOTE_PORT
REMOTE_USER
REMOTE_IDENT
REQUEST_METHOD
SCRIPT_FILENAME
PATH_INFO
QUERY_STRING
AUTH_TYPEDOCUMENT_ROOT
SERVER_NAME
SERVER_ADDR
SERVER_PORT
SERVER_PROTOCOL
SERVER_SOFTWARE
API_VERSION
THE_REQUEST
REQUEST_URI
REQUEST_FILENAME
HTTPS
TIME_YEAR
TIME_MON
TIME_DAY
TIME_HOUR
TIME_MIN
TIME_SEC
TIME_WDAY
TIMEAdditionally all special IIS server variables are supported.
CondPattern specifies a regular expression that will be applied to the instance of TestString. Following special values are also supported:
- Prefix regular expression with '!' symbol to specify negation pattern.
- '<CondPattern' Treats CondPattern as a plain string that will be lexicographically compared as more than.
- '>CondPattern' Lexicographically less then comparison.
- '=CondPattern' Lexicographically equals comparison.
- '-d' Test string is existing directory.
- '-f' Test string is existing file.
- '-s' Test string is a file with nonzero size.
- '-l' (link) Unsupported, always false.
- '-x' (has executable permissions) Unsupported, always true.
- '-F' (is existing file, via subrequest) Unsupported, same as '–f'.
- '-U' (is existing URL, via subrequest) Unsupported, always false.
The following flags are also supported:
- 'nocase|NC'
This flag makes the Pattern case-insensitive.
- 'ornext|OR'
This flag combines subsequent RewriteCond directives with logical OR instead of implicit AND.
- O
Leaved for compatibility with ISAPI_Rewrite 2.x. Normalizes string before processing. Normalization includes removing of an URL-encoding, illegal characters, etc. Also, IIS normalization of a URL completely removes query string from it.