Name

RewriteCond

Synopsis

RewriteCond TestString 
                     CondPattern
Server config, virtual host, directory

One or more RewriteCond directives can precede a RewriteRule directive to define conditions under which it is to be applied. CondPattern is a regular expression matched against the value retrieved for TestString, which contains server variables of the form %{ NAME_OF_VARIABLE }, where NAME_OF_VARIABLE can be one of the following list:

API_VERSION

PATH_INFO

SERVER_PROTOCOL

AUTH_TYPE

QUERY_STRING

SERVER_SOFTWARE

DOCUMENT_ROOT

REMOTE_ADDR

THE_REQUEST

ENV:any_environment_variable

REMOTE_HOST

TIME

HTTP_ACCEPT

REMOTE_USER

TIME_DAY

HTTP_COOKIE

REMOTE_IDENT

TIME_HOUR

HTTP_FORWARDED

REQUEST_FILENAME

TIME_MIN

HTTP_HOST

REQUEST_METHOD

TIME_MON

HTTP_PROXY_CONNECTION

REQUEST_URI

TIME_SEC

HTTP_REFERER

SCRIPT_FILENAME

TIME_WDAY

HTTP_USER_AGENT

SERVER_ADMIN

TIME_YEAR

HTTP:any_HTTP_header

SERVER_NAME

IS_SUBREQ

SERVER_PORT

These variables all correspond to the similarly named HTTP MIME headers, C variables of the Apache server, or the current time. If the regular expression does not match, the RewriteRule following it does not apply.

Get Apache: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.