title: HTTP to HTTPS Apache Rewrite not working
body: <p>I have an apache2 server running on Ubuntu that I am toying with to step my sys admin skills up. I've been trying to set up a webserver with HTTPS throughout the entire site. Currently, If I go to <a href="https://mysite.com" rel="nofollow">https://mysite.com</a> it works just fine. I've tried a few different redirect rules to make all connections to the site be forced to HTTPS, but I'm having no luck. Can anyone point out my mistake here?</p>
  
  <p>httpd.conf:</p>
  
  <pre><code>NameVirtualHost *:443
  
  &lt;VirtualHost *:443&gt;
          ServerName mysite.com
          ServerAdmin webmaster@localhost
          DocumentRoot /var/www/
          SSLEngine on
          SSLOptions +FakeBasicAuth -StrictRequire +ExportCertData
          SSLCertificateKeyFile /etc/ssl/crt/myserver.key
          SSLCertificateFile /etc/ssl/crt/mysite_com.crt
          SSLCertificateChainFile /etc/ssl/crt/mysite.ca-bundle
          &lt;Directory /&gt;
                  Options FollowSymLinks
                  AllowOverride None
          &lt;/Directory&gt;
          &lt;Directory /var/www/&gt;
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride AuthConfig Options FileInfo Limit
                  Order allow,deny
                  allow from all
          &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  
  &lt;IfModule !mod_rewrite.c&gt;
      LoadModule rewrite_module modules/mod_rewrite.so
  &lt;/IfModule&gt;
  
  
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  </code></pre>
  
  <p>ports.conf:</p>
  
  <pre><code>NameVirtualHost *:80
  Listen 80
  
  &lt;IfModule mod_ssl.c&gt;
      # If you add NameVirtualHost *:443 here, you will also have to change
      # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
      # to &lt;VirtualHost *:443&gt;
      # Server Name Indication for SSL named virtual hosts is currently not
      # supported by MSIE on Windows XP.
      Listen 443
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_gnutls.c&gt;
      Listen 443
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Any help is greatly appreciated!</p>