title: Redirect all www and http ==>> non www https on AWS Elastic Beanstalk with Load Balancer
body: <p>I currently have this in place to redirect all <code>http</code> traffic to <code>https</code>.</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !=https
  RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
  </code></pre>
  
  <p>The above is working OK. </p>
  
  <p>Now I'm trying to add rewrite condition to force all <code>https://www</code> traffic to <code>https</code> without the <code>www</code>.</p>
  
  <p>Please note that this is an AWS Elastic Beanstalk running Apache behind Elastic Load Balancer</p>
  
  <p>=============================</p>
  
  <p>EDIT:</p>
  
  <p><strong>Working code:</strong></p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
  RewriteCond %{HTTP_HOST} ^www\. [NC]
  RewriteCond %{SERVER_NAME} ^(www\.)?(.*)$ [NC]
  RewriteRule ^/?(.*)$ https://%2/$1 [L,R=301]
  </code></pre>