title: How can I redirect my subdomain from http to https using htaccess?
body: <p>I have created a subdomain on a website I'm developing and I want it to redirect to https automatically, particularly since if I try to access it by typing <a href="http://test.example.com" rel="nofollow noreferrer">http://test.example.com</a>, it doesn't work - it just appears to be waiting for a response from the server for a while (maybe 30 secs) before eventually resolving to <a href="https://www.test.example.com" rel="nofollow noreferrer">https://www.test.example.com</a> (is this a clue to the problem..?)
  I've tried adding a rule to catch all subdomains, in the .htaccess <strong>in the root of the website</strong>, like so:</p>
  
  <pre><code>RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.example\.com$
  RewriteRule ^ https://%1.example.com%{REQUEST_URI} [NE,L,R]
  </code></pre>
  
  <p>(...but to no avail)</p>
  
  <p>I've also tried a whole variety of other methods, in the htaccess file located in the <strong>home directory of the subdomain</strong>, as follows (one at a time of course):</p>
  
  <pre><code>#Method 1
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
  
  #Method 2
  RewriteCond %{HTTPS} off [NC,OR]
  RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://test.example.com/$1 [R=301,L]
  
  #Method 3
  RewriteCond %{HTTPS} off 
  RewriteCond %{HTTP_HOST} =test.example.com
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301]
  
  #Method 4
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.example\.com$
  RewriteRule ^ https://%1.example.com%{REQUEST_URI} [NE,L,R]
  
  #Method 5
  RewriteCond %{HTTP_HOST} ^(.*?)\.example.com$
  RewriteCond %{HTTPS} !=on
  RewriteRule ^(.*?)$ https://%{HTTP_HOST} [nc]
  </code></pre>
  
  <p>None of these redirect the <a href="http://test.example.com" rel="nofollow noreferrer">http://test.example.com</a> subdomain to https - they do nothing except Method 2 which returns a 'too many redirects' error.
  What am I missing here.?
  Thank you</p>