title: Exclude directory from rewrite rule
body: <p>Below is my .htaccess file. I am trying to exclude the rewrite rules being applied to the /admin/ folder, however after spending an hour researching and trying various codes I have reached a wall.</p>
  
  <pre><code>Options -MultiViews
  RewriteEngine On
  
  RewriteBase /
  
  # Exclude admin directory    
  RewriteRule ^(admin|admin)($|/) - [L]
  
  RewriteRule ^privacy$ pages/privacy.php [NC,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/(.*)/(.+)$ products.php?q=$3&amp;rewrite=1&amp;%{QUERY_STRING} [L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)/(.*)/$ search.php?q=bw:&amp;categoryFilter=$1&amp;genreFilter=$2%{QUERY_STRING} [L,B]
  
  RewriteRule ^(.*)/$ pages/format.php?format=$1 [NC,L}   
  
  RewriteCond %{REQUEST_URI} !(/$|\.) 
  RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 
  </code></pre>
  
  <p>The above code brings an internal 500 error and if I remove it will redirect me to the rewrite rule for the format. I was reading that The exclusion rewrite rule needs to be placed before the rule I want to overwrite. I don't understand why it's not working and what I have missed.</p>
  
  <p>Thanks.</p>