title: .htaccess and environment variables (do X if Env isnt)
body: <p>Morning,</p>
  
  <p>I've got 2 entries in my .htaccess file, and I want to make them a little more dynamic.</p>
  
  <p>Firstly I've got a non-www to www. redirect</p>
  
  <pre><code> &lt;IfModule mod_rewrite.c&gt;
      RewriteCond %{HTTPS} !=on
      RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
      RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
   &lt;/IfModule&gt;
  </code></pre>
  
  <p>However, i'd like it to function conditionally as below</p>
  
  <pre><code> &lt;IfModule mod_rewrite.c&gt;
      RewriteCond %{ENV:environment} != "dev" &amp;&amp; != "local"
      RewriteCond %{HTTP_HOST} {DOESNT_CONTAIN .staging.com}
      RewriteCond %{HTTPS} !=on
      RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
      RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
   &lt;/IfModule&gt;
  </code></pre>
  
  <p>So basically, I want the www. redirect to kick in if the env variable doesnt equal dev or local, and the domain doesnt have .staging.com in it</p>
  
  <p>How would I go about sorting this?</p>
  
  <p>Secondly, this is pretty much an identical issue, I've got some authentication</p>
  
  <pre><code>Order deny,allow
  Deny from all
  AuthType Basic
  AuthUserFile /var/www/vhosts/{HTTP_HOST}/httpdocs/.htpasswd
  AuthName "Protected Area"
  require valid-user
  Allow from 127.0.0.1
  Satisfy Any
  </code></pre>
  
  <p>I would like this to only run on the same conditions as above so:
  environment != "local"
  environment != "dev"
  url doesnt contain .staging.com</p>
  
  <p>Hope some of you could shed some light onto this issue please.</p>
  
  <p>Many thanks!</p>