title: force https on subdirectory and redirect non-www traffic to www
body: <p>So for the past couple hours I've been frustrated with my .htaccess file not working.</p>
  
  <p>I have two subdirectories: secure.mysite.ca and storage.mysite.ca that need to be both ssl encrypted. The sites work when I put https in front of the URL (i.e. <a href="https://secure.mysite.ca/" rel="nofollow">https://secure.mysite.ca/</a> or <a href="https://storage.mysite.ca/" rel="nofollow">https://storage.mysite.ca/</a>) but when I put http in front it redirects to my root website (<a href="http://mysite.ca/" rel="nofollow">http://mysite.ca/</a>). I want to redirect to the https version of the site when someone tries to go to the unencrypted version.</p>
  
  <p>ALSO I would like to redirect all traffic visiting <a href="http://mysite.ca/" rel="nofollow">http://mysite.ca/</a> to be redirected to <a href="http://www.mysite.ca/" rel="nofollow">http://www.mysite.ca/</a> (i.e. www in front)</p>
  
  <p>This .htaccess file used to work over a year ago but now it doesn't.</p>
  
  <p>Here is my htaccess file found in the root folder:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP_HOST} ^mysite\.ca$ [NC]
  RewriteRule ^(.*)$ http://www.mysite.ca%{REQUEST_URI} [R=permanent,L]
  
  RewriteCond %{SERVER_PORT} !^443$
  RewriteCond %{HTTP_HOST} ^(secure|storage)\. [NC]
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]  
  </code></pre>
  
  <p>Am I doing something wrong? Should I be putting an .htaccess file inside the subdirectory?</p>
  
  <p>EDIT: Here is the virtualhost config file for secure.fixnode.ca, storage.fixnode.ca and www.fixnode.ca. Please let me know what I'm doing wrong</p>
  
  <p>storage.fixnode.ca.conf</p>
  
  <pre><code>&lt;VirtualHost *:443&gt;
  DocumentRoot "/var/www/fixnode_website/content/Online Storage"
  &lt;Directory "/var/www/fixnode_website/content/Online Storage"&gt;
  allow from all
  Options +Indexes
  &lt;/Directory&gt;
  SSLEngine on
  ServerName storage.fixnode.ca
  SSLCertificateFile /path/to/cert/storage.crt
  SSLCertificateKeyFile /path/to/private key/private.key
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>secure.fixnode.ca.conf</p>
  
  <pre><code>&lt;VirtualHost *:443&gt;
  DocumentRoot "/var/www/fixnode_website/content/Secure Login"
  &lt;Directory "/var/www/fixnode_website/content/Secure Login"&gt;
  allow from all
  Options +FollowSymlinks
  &lt;/Directory&gt;
  SSLEngine on
  ServerName secure.fixnode.ca
  SSLCertificateFile /path/to/cert/cert.crt
  SSLCertificateKeyFile /path/to/cert/mykey.key
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>and finally my virtual host for my root domain www.fixnode.ca.conf</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  DocumentRoot /var/www/fixnode_website
  &lt;Directory "/var/www/fixnode_website"&gt;
  allow from all
  Options +Indexes
  &lt;/Directory&gt;
  ServerAlias fixnode.ca
  ServerName www.fixnode.ca
  &lt;/VirtualHost&gt;
  </code></pre>