title: What's correct htaccess rule to redirect mixed content to HTTPS
body: <p>Is there a way with htaccess redirect conditions and redirects to catch content called over HTTP when the site is accessed via HTTPS?</p>
  
  <p>Such that http content will be redirected to the https equivalent url if the site is accessed over HTTPS?</p>
  
  <p>Essentially I'd like a automated way to mop up and deal with mixed content when my site is accessed via HTTPS.</p>
  
  <p>So far the following fixed all .css and .js files being called over HTTP when site is accessed through HTTPS.</p>
  
  <pre><code>RewriteRule ^/(.*):SSL$   https://%{SERVER_NAME}/$1 [R,L]
  RewriteRule ^/(.*):NOSSL$ http://%{SERVER_NAME}/$1 [R,L]
  </code></pre>
  
  <p>But for some reason this does not redirect requests for images (for instance) on my site being called through HTTP during an HTTPS session.</p>
  
  <p>I also tried this rule,</p>
  
  <pre><code>RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  </code></pre>
  
  <p>but that didn't redirect the images either.</p>
  
  <p>I figure there must be a way to test if connection is over HTTPS, then rewrite any http:// urls to an https:// equivalent. I am just not sure how to formula the rules correctly.</p>