July 22, 2008

Mod_rewrite: RewriteCond

Filed under: Uncategorized — kenjun @ 9:49 am

For a plain English translation, go down to the end…

Syntax: RewriteCond TestString CondPattern

The RewriteCond directive defines a rule condition. Precede a RewriteRule directive with one or more RewriteCond directives. The following rewriting rule is only used if its pattern matches the current state of the URI and if these additional conditions apply too.

TestString is a string which can contains the following expanded constructs in addition to plain text:
– RewriteRule backreferences
– RewriteCond backreferences
– RewriteMap expansions
– Server-Variables

Note that this is a simplified version of what’s at
which goes on for several pages about this in vast detail.

To put it into plain English:
Say you have this (as can be found in a CodeIgniter .htaccess file):
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

What this means is:
IF the incoming Request URI (ie the address requested by the browser) matches “system”
THEN rewrite it so that it uses the index.php file in the root directory.

For explanation of RewriteRule see an earlier post.


Blog at

%d bloggers like this: