<p>In an application that heavily relies on <code>.htaccess</code> RewriteRules for its PrettyURLs (CakePHP in my case), how do I correctly set up directives to exclude certain directories from this rewriting? That is:</p>

<pre><code>/appRoot/.htaccess
         app/
         static/
</code></pre>

<p>By default every request to <code>/appRoot/*</code> is being rewritten to be picked up by <code>app/webroot/index.php</code>, where it's being analysed and corresponding controller actions are being invoked. This is done by these directives in <code>.htaccess</code>:</p>

<pre><code>RewriteBase /appRoot

RewriteRule ^$ app/webroot/     [L]
RewriteRule (.*) app/webroot/$1 [L]
</code></pre>

<p>I now want to exclude a few directories like static/ from this rewriting. I tried with this <em>before</em> the Cake RewriteRules:</p>

<pre><code>RewriteCond $1 ^(static|otherDir).*$ [NC]
RewriteRule (.*) - [L]
</code></pre>

<p>It works in so far that requests are no longer rewritten, but now <strong>all</strong> requests are being skipped, even legitimate Cake requests which should not match <code>^(static|otherDir).*$</code>.</p>

<p>I tried several variations of these rules but can't get it to work the way I want.</p>

[{'answer_id': 3159, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 1, 'selected': False, 'text': '<p>Remove the [L] from the previous rules:</p>\n\n<pre><code>RewriteBase /appRoot\n\nRewriteRule ^$ app/webroot/ &amp;nbsp; &amp;nbsp;\nRewriteRule (.*) app/webroot/$1\n</code></pre>\n\n<p>[L] means "Stop the rewriting process here and don\'t apply any more rewriting rules."</p>\n'}, {'answer_id': 3161, 'author': 'Lauren', 'author_id': 265, 'author_profile': 'https://Stackoverflow.com/users/265', 'pm_score': 1, 'selected': False, 'text': "<p>Could you not apply the condition to the following rules, but with negation, as in (with some variation thereof, I'm not too good at remembering .htaccess rules, so the flags might be wrong):</p>\n\n<pre><code>RewriteCond $1 !^(static|otherDir).*$ [NC]\nRewriteRule ^$ app/webroot/ [L]\n\nRewriteCond $1 !^(static|otherDir).*$ [NC]\nRewriteRule ^$ app/webroot/$1 [L]\n</code></pre>\n"}, {'answer_id': 4449, 'author': 'deceze', 'author_id': 476, 'author_profile': 'https://Stackoverflow.com/users/476', 'pm_score': 4, 'selected': True, 'text': "<p>And the correct answer iiiiis...</p>\n\n<pre><code>RewriteRule   ^(a|bunch|of|old|directories).* - [NC,L]\n\n# all other requests will be forwarded to Cake\nRewriteRule   ^$   app/webroot/   [L]\nRewriteRule   (.*) app/webroot/$1 [L]\n</code></pre>\n\n<p>I still don't get why the index.php file in the root directory was called initially even with these directives in place. It is now located in</p>\n\n<pre><code>/appRoot/app/views/pages/home.ctp\n</code></pre>\n\n<p>and handled through Cake as well. With this in place now, I suppose this would have worked as well (slightly altered version of Mike's suggestion, untested):</p>\n\n<pre><code>RewriteCond $1      !^(a|bunch|of|old|directories).*$ [NC]\nRewriteRule ^(.*)$  app/webroot/$1 [L]\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/3157', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/476/']