title: Force SSL in .htaccess or in my PHP code, results in redirect loop error
body: <p>I am attempting to force the use of HTTPS, I am hopeful to accomplish this with the .htaccess file, but have also attempted to use code. I am using Zend framework, and have tried to use this code in the <code>Bootstrap.php</code> in attempt in avoiding a conflicting rule or some erroneous setting on the HTTP server.</p>
  
  <pre><code>public function _initForceSSL() {
      if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
          if(!headers_sent()) {
              header("Status: 301 Moved Permanently");
              header(sprintf(
                  'Location: https://%s%s',
                  $_SERVER['HTTP_HOST'],
                  $_SERVER['REQUEST_URI']
              ));
              exit();
          }
      }
  }
  </code></pre>
  
  <p>This produces the same results as if I where to do this...</p>
  
  <pre><code>RewriteCond %{SERVER_PORT} 80 
  RewriteRule ^(.*)$ https://mydomain.tld/$1 [R,L]
  </code></pre>
  
  <p>in my .htaccess file. I get the same redirect loop complaint on my local dev. server (where I have full access to all settings, regular 'ol LAMP stack it is). Also, same results on Zend's PHPCloud (using Zend server). </p>
  
  <p>Here is my full .htacces file, I've tried using the rules in various places...</p>
  
  <pre><code>    setEnv APPLICATION_ENV development
  
      #setEnv APPLICATION_ENV production
      #setEnv APPLICATION_ENV testing
  
      RewriteEngine On 
  
  #tried it here
  
      RewriteCond %{REQUEST_FILENAME} -s [OR]
      RewriteCond %{REQUEST_FILENAME} -l [OR]
      RewriteCond %{REQUEST_FILENAME} -d
  #tried here
      RewriteBase /
      RewriteRule ^.*$ - [NC,L]
      RewriteRule ^.*$ index.php [NC,L]
  
  #tried it here too...
  </code></pre>
  
  <p>I just can't seem to figure out what I'm doing wrong, I've attempted a few other 'popular' method for a rewrite as well. Also, btw I do use my actual domain name in the RewriteRule.</p>
  
  <p>My only requirement is that the entire application NOT be available over a non secure connection (SSL Only).</p>