<p>I have a website that employs a generic mod_rewrite rule to push all requests to the index.php page, with the exception of certain file extensions:</p>

<pre><code>RewriteRule !\.(js|ico|gif|jpg|JPG|png|css|php|phtml|pdf|txt|xml)$ index.php
</code></pre>

<p>What I need to be able to do is also exclude a certain directory (including any files or sub-directories contained within) from this rule - what is the best solution?</p>

<p>Here is my full .htaccess file, in case something else within it is intefering:</p>

<pre><code>RewriteEngine ON
RewriteCond %{HTTP_HOST} !^www\..*
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST} ^([^.]*)\.(co\.uk)
RewriteRule ^.*$     http://www.%1.%2%{REQUEST_URI} [R=permanent,L]

AddHandler application/x-httpd-php .phtml

RewriteRule !\.(js|ico|gif|jpg|JPG|png|css|php|phtml|pdf|txt|xml)$ index.phtml

php_value display_errors "On"
</code></pre>

You could check with
```
RewriteCond %{REQUEST_FILENAME} !-f
```
for any request that doesn't match to an existing filename.