title: .htaccess - stop processing if rewriterule true?
body: <p>Here is my .htaccess file:</p>
  
  <pre><code>Options +FollowSymlinks
  RewriteEngine on
  
  Rewritecond %{http_host} ^mysite.com [nc]
  Rewriterule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]
  
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteCond %{REQUEST_FILENAME} !-f 
  RewriteRule . /404.php
  </code></pre>
  
  <p>The 1st rewritecond / rewriterule block is to redirect the user to www if they entered the address without www.</p>
  
  <p>The 2nd rewritecond / rewriterule block is to redirect the user to a page that I created if they enter a non-existent address.</p>
  
  <p>Each of these rules works on its own:</p>
  
  <p>If my .htaccess file contains only the first block, then it successfully redirects non-www addresses to the www address.</p>
  
  <p>And if a non-existent address is entered, the user is successfully redirected to my page 404.php.</p>
  
  <p>However, if the .htaccess file contains both blocks, and a non-www address is entered, then instead of a successful redirection to the www address, the following happens:</p>
  
  <p>(1) The following is displayed on the page:</p>
  
  <p>Moved Permanently</p>
  
  <p>The document has moved here.</p>
  
  <p>Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.</p>
  
  <p>Apache/1.3.41 Server at mysite.com Port 80</p>
  
  <p>(2) The following entry is generated in the error log:</p>
  
  <p>[Fri May  4 01:54:19 2012] [error] [client 109.109.109.109] mod_rewrite:
  maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.</p>
  
  <p>I assume that what happens is that an infinite loop is somehow being generated.</p>
  
  <p>I'm wondering if telling the .htaccess file to stop processing commands if the first condition has been met would solve the problem. So does anyone know how to do this?</p>
  
  <p>(Side note. In general, I find the documentation out there on .htaccess to be absolutely horrendous. I wonder if anyone else feels similarly.)</p>
  
  <p>Thanks in advance.</p>