title: Force SSL HTTPS for subdomain with .htaccess
body: <p>I have this code for forcing SSL on a website generally:</p>
  
  <pre><code>RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  </code></pre>
  
  <p>Which I got from <a href="http://www.easylaravelbook.com/blog/2015/05/27/redirecting-to-https-in-laravel-5/" rel="noreferrer">here</a></p>
  
  <p>I would like it to <strong>only apply to a specific sub-domain</strong>.</p>
  
  <p>For example, if you were to visit <code>http://sub.domain.org</code> it should redirect to <code>https://sub.domain.org</code>.</p>
  
  <p>I have a hunch that I need to add another <code>RewriteCond</code> which basically says <em>is the domain that is being hit is <a href="http://sub.domain.org" rel="noreferrer">http://sub.domain.org</a></em>, but I am at a loss on how to write this code.</p>
  
  <p>I've been looking at other stackoverflow questions such as:</p>
  
  <p><a href="https://stackoverflow.com/questions/20894947/force-https-and-www-for-domain-and-only-https-for-subdomains-htacess">Force HTTPS and WWW for domain and only HTTPS for subdomains HTACESS</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite">Force SSL/https using .htaccess and mod_rewrite</a></p>
  
  <p>and the Apache docs: <a href="https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond" rel="noreferrer">https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond</a></p>
  
  <p>And I've had these attempts:</p>
  
  <pre><code>RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^(reports\.)?uksacb\.org$ [NC]
  RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]
  </code></pre>
  
  <p>Sort of reversed the answer in this <a href="https://stackoverflow.com/questions/10789598/htaccess-redirect-to-https-except-subdomain">question/answer</a>:</p>
  
  <pre><code>RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} =reports.uksacb.org
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  </code></pre>
  
  <p>However I'm still failing to make sense of how to do it correctly.</p>
  
  <p>If anyone could explain to me what I'm doing wrong, what I need to do to get it right and how does one go about debugging their rewrite conditions and rules to make sure it works properly I'd be very grateful. Sometimes I think my browser is caching the rules I've written and my different attempts are not taking any affect!</p>
  
  <p>My whole <code>.htaccess</code> looks like this:</p>
  
  <p>
      
          Options -MultiViews
      </p>
  
  <pre><code>RewriteEngine On
  
  # Redirect Trailing Slashes If Not A Folder...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  
  # Force SSL
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
  # Handle Front Controller...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
  </code></pre>
  
  <p></p>