title: Reuse subdomain in a rewrite rule
body: <p>I'm a bit stuck with my redirect rule. Little example better than a long speech, here goes the Great Ugliness:</p>
  
  <pre><code>IndexIgnore *
  ErrorDocument 404 http://www.example.com
  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^www\.  [NC]
  RewriteRule ^([^\.]+)\.example\.com$ http://example.com/private/$1/public/si.php  [L]
  </code></pre>
  
  <p>My objective is to get the subdomain <code>([^\.]+)</code> and use it in the redirection instead of <code>$1</code>.
  For example, <code>test.example.com</code> should redirect to <code>http://example.com/private/test/public/si.php</code></p>
  
  <p>Thank you for any help.</p>
  
  <p>Regards, 
  S.</p>
  
  <p>final working htaccess:</p>
  
  <pre><code>RewriteEngine on
  RewriteCond %{HTTP_HOST} !^www\.  [NC]
  RewriteCond %{REQUEST_URI} !^/private/
  RewriteCond %{HTTP_HOST} ([^\.]+).example.com [NC]
  RewriteRule ^ /private/%1/public/$1  [R=301,L]
  </code></pre>
  
  <p>redirects <code>anysub.example.com/anypage</code> to <code>anysub.example.com/private/anysub/public/anypage</code></p>