title: How do I use .htaccess to redirect to a URL containing HTTP_HOST?
body: <p><strong>Problem</strong></p>
  
  <p>I need to redirect some short convenience URLs to longer actual URLs. The site in question uses a set of subdomains to identify a set of development or live versions.</p>
  
  <p>I would like the URL to which certain requests are redirected to include the HTTP_HOST such that I don't have to create a custom .htaccess file for each host.</p>
  
  <p><strong>Host-specific Example (snipped from .htaccess file)</strong></p>
  
  <pre><code>Redirect /terms http://support.dev01.example.com/articles/terms/
  </code></pre>
  
  <p>This example works fine for the development version running at dev01.example.com. If I use the same line in the main .htaccess file for the development version running under dev02.example.com I'd end up being redirected to the wrong place.</p>
  
  <p><strong>Ideal rule (not sure of the correct syntax)</strong></p>
  
  <pre><code>Redirect /terms http://support.{HTTP_HOST}/articles/terms/
  </code></pre>
  
  <p>This rule does not work and merely serves as an example of what I'd like to achieve. I could then use the exact same rule under many different hosts and get the correct result.</p>
  
  <p><strong>Answers?</strong></p>
  
  <ul>
  <li>Can this be done with mod_alias or does it require the more complex mod_rewrite?</li>
  <li>How can this be achieved using mod_alias or mod_rewrite? I'd prefer a mod_alias solution if possible.</li>
  </ul>
  
  <p><strong>Clarifications</strong></p>
  
  <p>I'm not staying on the same server. I'd like:</p>
  
  <ul>
  <li>http://<strong>example.com</strong>/terms/ -> <a href="http://support" rel="nofollow noreferrer">http://support</a>.<strong>example.com</strong>/articles/terms/</li>
  <li><a href="https://secure" rel="nofollow noreferrer">https://secure</a>.<strong>example.com</strong>/terms/ -> <a href="http://support" rel="nofollow noreferrer">http://support</a>.<strong>example.com</strong>/articles/terms/</li>
  <li>http://<strong>dev.example.com</strong>/terms/ -> <a href="http://support" rel="nofollow noreferrer">http://support</a>.<strong>dev.example.com</strong>/articles/terms/</li>
  <li><a href="https://secure" rel="nofollow noreferrer">https://secure</a>.<strong>dev.example.com</strong>/terms/ -> <a href="http://support" rel="nofollow noreferrer">http://support</a>.<strong>dev.example.com</strong>/articles/terms/</li>
  </ul>
  
  <p>I'd like to be able to use the same rule in the .htaccess file on both example.com and dev.example.com. In this situation I'd need to be able to refer to the HTTP_HOST as a variable rather than specifying it literally in the URL to which requests are redirected.</p>
  
  <p>I'll investigate the HTTP_HOST parameter as suggested but was hoping for a working example.</p>