Force SSL in .htaccess or in my PHP code, results in redirect loop error

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 Bootstrap.php in attempt in avoiding a conflicting rule or some erroneous setting on the HTTP server.

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();
        }
    }
}

This produces the same results as if I where to do this...

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://mydomain.tld/$1 [R,L]

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).

Here is my full .htacces file, I've tried using the rules in various places...

    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...

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.

My only requirement is that the entire application NOT be available over a non secure connection (SSL Only).

How to add subdomain on local machine

I have modified my etc/hosts file (under Windows 7), so that www.example.com and demo.example.com both point at localhost. Unfortunately accessing demo.example.com, takes me to localhost's document root (which is logical). I want to change this to point demo.example.com to demo.localhost, so make a new virtual subdomain on localhost and then the etc/hosts file should do it's work.

Could anyone point me in the right direction? I have this vhosts file, which has a valid syntax, but doesn't seem to be working as I want.

<VirtualHost 127.0.0.1:80>
ServerPath /demo-example/
ServerName demo.example.com
</VirtualHost>

Tomcat is not running even though JAVA_HOME path is correct

When I am trying to run tomcat using startup.bat I get the following error,

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

But then I try C:\>echo %java_home% and I get the following result

C:\Program Files\Java\jdk1.6.0_25\bin

I have even tried setting JAVA_HOME manually to system variable list, but this issue remains.

What can I do to solve it?

I am using Windows 7.


Update

After setting a new system variable named JAVA_HOME and setting its path to "C:\Program Files\Java\jdk1.6.0_25\bin\", I tried the start up script again and this time I get a new error.

D:\Work\apache-tomcat-6.0.35\bin>startup.bat
Files\Java\jdk1.6.0_25"" was unexpected at this time.

Any idea what this error means?

I even tried setting the path to "C:\Program Files\Java\jdk1.6.0_25\"(that is without bin) but same error occurs.