title: htaccess redirect to sub folder compatible with localhost and real domain
body: <p>I want to redirect my urls via htaccess from a particular sub-folder to main domain.</p>
  
  <p>One option is to use the following rule</p>
  
  <pre><code>RewriteRule ^subfolder/(pattern)$ http://%{HTTP_HOST}/$1 [R=301,L]
  </code></pre>
  
  <p>works fine for real domain</p>
  
  <pre><code>redirects correctly
  http://example.com/subfolder/page
  to
  http://example.com/page
  </code></pre>
  
  <p>works incorrectly for localhost</p>
  
  <pre><code>redirects
  http://localhost/exmple/subfolder/page
  to
  http://localhost/page
  instead of 
  http://localhost/exmple/page
  </code></pre>
  
  <p>modifying the rule as follows works for localhost but not for real domain</p>
  
  <pre><code>RewriteRule ^subfolder/(pattern)$ http://%{HTTP_HOST}/example/$1 [R=301,L]
  </code></pre>
  
  <p>I use localhost environment for development and testing before uploading the script to the host web server.</p>
  
  <p>Please tell if this is possible to handle the above scenario in a generic way so that I don't need to maintain two copies of code/htaccess - one for local and one for real domain.</p>