title: .htaccess RewriteRule - DOCUMENT_ROOT and RewriteBase
body: <p>I have a <em>secure/</em> sub-directory with several files that I want to perform some simple RewriteRules on, just defaulting a PHP extension. I had a hard time getting these to work and after some trial and error stumbled upon the following.</p>
  
  <pre><code>RewriteEngine On
  RewriteBase /secure
  
  # Force PHP extension if not a directory
  RewriteCond %{DOCUMENT_ROOT}/secure/%{REQUEST_URI} -d
  RewriteRule ^(.*)$ - [L]
  
  RewriteCond %{DOCUMENT_ROOT}/secure/$1.php -f
  RewriteRule ^((.*/)*[^./]+)/*$ $1.php [L]
  </code></pre>
  
  <p>My lack of understanding is around <code>%{DOCUMENT_ROOT}</code> and appending <code>/secure/</code>. I believed either <code>%{DOCUMENT_ROOT}</code> or using the <code>RewriteBase</code> would handle this. However, each of these pieces seems to be required. I'd like to know why and what each achieves in my case.</p>