title: In .htaccess, how to redirect non-lowercase versions of hostname
body: <p>In <code>.htaccess</code> on Apache2, how do you redirect all capitalization variations of a hostname to a canonical lowercase version, via 301 redirect, and keeping the rest of the path unharmed. Subdomains (or not) should do the same as well. </p>
  
  <p>Additionally, accessing via an IP should <em>not</em> redirect.</p>
  
  <p>examples:</p>
  
  <ul>
  <li><code>http://Example.com/foo</code> => <code>http://example.com/foo</code></li>
  <li><code>http://A.example.com/foo</code> => <code>http://a.example.com/foo</code></li>
  <li><code>http://A.EXample.com/foo?bar</code> => <code>http://a.example.com/foo?bar</code></li>
  <li><code>http://208.67.222.222/foo</code> => <code>http://208.67.222.222/foo</code></li>
  </ul>