We help IT Professionals succeed at work.

htaccess condition


My .htaccess file has the following content:

SetEnv PHP_VER 5
RewriteEngine on
RewriteCond %{REQUEST_URI} !/img.*
RewriteCond %{REQUEST_URI} !/admin.*
RewriteBase /
RewriteCond %{REQUEST_URI} !/javascript.*
RewriteRule !\.(js|ico|gif|jpg|png|css|swf)$ index.php

So all the requests are forwarded to index.php
But I want to add a rule:
if there is a request to googlehostedservice.html or to info.php,
I do not want to forward to index.php
Also if someone can explain me the RewriteCond instructions.

Thank you.
Watch Question

Top Expert 2004
You can see all the information on mod_rewrite here:


The rewrite rules and conditions are based in regular expressions.  For example, !\.(js|ico|gif|jpg|png|css|swf)$:

! = not operator.  Means the condition will be true if the expression is NOT matched.
\. = an actual period character.  The slash is called an escape character, and is used to indicate that the next character should be interpreted literally.  Normally, regex sees a period as a marker for 'any character'
$ = end of line marker.  This is generally used to indicate an EOL character (\n or \r\n), though I believe it means end-of-input in this context.
(js|ico|gif|jpg|png|css|swf) = indicates several alternatives that should be accepted as a match.  This is a parenthetical list, delimited by pipe (|) characters.

Combining all of those together:

If the request URI being submitted does NOT include a period, followed by js or ico or gif or jpg or png or css or swf, followed immediately by the end of input, then this condition applies.

You can find more information about how to build regular expressions here:


For your new rule, try adding the following lines:

RewriteCond %{REQUEST_URI}	!googlehostedservice.html [NC]
RewriteCond %{REQUEST_URI}	!info.php [NC]

Open in new window


Thank you,

what is [NC] for ?
it seems to work without
Top Expert 2004

[NC] is a modifier indicating no case sensitivity is to be used for the comparison.  Without the [NC] modifier, info.php would violate the condition, where INFO.php would match it.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.